8 describe "#extract_hosts_from_json" do
9 it "should fail for non array data" do
11 Helpers.extract_hosts_from_json("{}")
12 }.to raise_error("JSON hosts list is not an array")
15 it "should fail for non hash array members" do
16 senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, ""].to_json
19 Helpers.extract_hosts_from_json(senders)
20 }.to raise_error("JSON host list is not an array of Hashes")
23 it "should fail for hashes without senders" do
24 senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {}].to_json
27 Helpers.extract_hosts_from_json(senders)
28 }.to raise_error("JSON host list does not have senders in it")
31 it "should return all found unique senders" do
32 senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {"sender" => "sender1"}].to_json
34 Helpers.extract_hosts_from_json(senders).should == ["sender1", "sender3"]
38 describe "#extract_hosts_from_array" do
39 it "should support single string lists" do
40 Helpers.extract_hosts_from_array("foo").should == ["foo"]
43 it "should support arrays" do
44 Helpers.extract_hosts_from_array(["foo", "bar"]).should == ["foo", "bar"]
47 it "should fail for non string array members" do
49 Helpers.extract_hosts_from_array(["foo", 1])
50 }.to raise_error("1 should be a string")