require 'test_helper' require 'simple_aws/core/util' describe SimpleAWS::Util do def remove_whitespace_from(string) string.gsub(/^\s*/, "").gsub(/\n/, "") end describe "#build_xml_from" do it "takes a hash and builds XML" do response = SimpleAWS::Util.build_xml_from :RootNode => { :InnerNode => "Value" } remove_whitespace_from(response).must_equal %|Value| end it "will add namespace to the root node" do response = SimpleAWS::Util.build_xml_from( {:RootNode => { :InnerNode => "Value" }}, "http://cloudfront.amazonaws.com/doc/2010-11-01/" ) remove_whitespace_from(response).must_equal %|Value| end it "works with arrays of items" do response = SimpleAWS::Util.build_xml_from( {:RootNode => { :InnerNode => ["Value1", "Value2", "Value3"] }} ) remove_whitespace_from(response).must_equal %|Value1Value2Value3| end it "works at any nestedness of hashes" do response = SimpleAWS::Util.build_xml_from( :RootNode => { :InnerNode => [ {:Child => "Value1"}, {:Child => "Value2"} ] } ) remove_whitespace_from(response).must_equal %|Value1Value2| end it "auto-strings all leaf nodes" do response = SimpleAWS::Util.build_xml_from( :RootNode => { :BoolVal => true, :Number => 12, :BadBool => false } ) response.must_match(%r{true}) response.must_match(%r{12}) response.must_match(%r{false}) end end end