require File.join(File.dirname(__FILE__), "..", "helper") class HashToXmlTest < Test::Unit::TestCase context "Calling hash_to_xml" do setup { ApricotEatsGorilla.sort_keys = true } context "with a Hash consisting of a single key-value-pair" do should "returns an XML String containing one node and a value" do hash = { "apricot" => "eats gorilla" } expected = "eats gorilla" result = ApricotEatsGorilla.hash_to_xml(hash) assert_equal expected, result end end context "with a Hash containing another Hash" do should "returns an XML String representing the given structure" do hash = { "apricot" => { "eats" => "gorilla", "drinks" => "beer" } } expected = "beergorilla" result = ApricotEatsGorilla.hash_to_xml(hash) assert_equal expected, result end end context "with a Hash containing a Hash containing an Array" do should "returns an XML String representing the given structure" do hash = { "apricot" => { "eats" => [ "gorilla", "snake" ] } } expected = "gorillasnake" result = ApricotEatsGorilla.hash_to_xml(hash) assert_equal expected, result end end context "with a Hash containing a Hash containing an Array containing a Hash" do should "returns an XML String representing the given structure" do hash = { "apricot" => { "eats" => [ { "lotsOf" => "gorillas" }, { "justSome" => "snakes" } ] } } expected = "gorillas" << "snakes" result = ApricotEatsGorilla.hash_to_xml(hash) assert_equal expected, result end end end end