require File.join(File.dirname(__FILE__), "..", "helper")
class XmlToHashTest < Test::Unit::TestCase
context "Calling xml_to_hash" do
setup { ApricotEatsGorilla.sort_keys = true }
context "with a SOAP response example and a custom root node" do
should "return a Hash containing the XML content" do
xml = '
secret
example
'
expected = { :auth_value => { :token => "secret", :client => "example" } }
result = ApricotEatsGorilla.xml_to_hash(xml, "//return")
assert_equal expected, result
end
end
context "with XML containing 'true' and 'false' Strings" do
should "convert these Strings into actual Boolean objects" do
xml = "truefalsesomething"
expected = { :yes => true, :no => false, :text => "something" }
result = ApricotEatsGorilla.xml_to_hash(xml)
assert_equal expected, result
end
end
context "with XML containing empty element tags" do
should "convert empty element tags to nil" do
xml = "Jungle Julia"
expected = { :name => "Jungle Julia", :email => nil, :phone => nil }
result = ApricotEatsGorilla.xml_to_hash(xml)
assert_equal expected, result
end
end
context "with XML containing nodes with attributes" do
should "return a Hash without tag attributes" do
xml = 'black'
expected = { :paint => "black" }
result = ApricotEatsGorilla.xml_to_hash(xml)
assert_equal expected, result
end
end
context "with XML containing nodes with the same name" do
should "group these nodes into an Array" do
xml = "firstsecond"
expected = { :items => [ "first", "second" ] }
result = ApricotEatsGorilla.xml_to_hash(xml)
assert_equal expected, result
end
end
end
end