require File.join(File.dirname(__FILE__), "..", "spec_helper") describe ApricotEatsGorilla do include SpecHelper # hash_to_xml describe "hash_to_xml" do before { reset_library_options } it "converts Hash key Symbols into Strings" do hash = { :apricot => { :eats => [ :gorilla, "snake" ] } } ApricotEatsGorilla.hash_to_xml(hash).should == "gorillasnake" end it "converts lowerCamelCase Hash keys to snake_case" do hash = { :apricot => { :eats => { :lots_of => "gorillas" } } } ApricotEatsGorilla.hash_to_xml(hash).should == "gorillas" end it "does not convert lowerCamelCase Hash keys to snake_case if this was disabled" do ApricotEatsGorilla.disable_tag_names_to_lower_camel_case = true hash = { :apricot => { :eats => { :lots_of => "gorillas" } } } ApricotEatsGorilla.hash_to_xml(hash).should == "gorillas" end it "converts values responding to to_s into Strings" do hash = { :apricot => { :with => 100.01, :when => nil, :what => :gorillas } } ApricotEatsGorilla.hash_to_xml(hash).should == "gorillas" << "100.01" end it "converts DateTime objects into Strings matching the SOAP date format" do date = DateTime.new(y=2009,m=9,d=1, h=12,min=0,s=8) hash = { :apricot => { :eats => { :at => date } } } ApricotEatsGorilla.hash_to_xml(hash).should == "2009-09-01T12:00:08" end it "applies namespaces nodes defined via nodes_to_namespace" do ApricotEatsGorilla.nodes_to_namespace = { :wsdl => [ :apricot ] } hash = { :apricot => { :eats => "Gorilla" } } ApricotEatsGorilla.hash_to_xml(hash).should == "Gorilla" end it "converts a Hash containing only one key and a value into one node with content" do hash = { "apricot" => "eats Gorilla" } ApricotEatsGorilla.hash_to_xml(hash).should == "eats Gorilla" end it "converts a nested Hash into nested nodes" do hash = { "apricot" => { "eats" => "gorilla", "drinks" => "beer" } } ApricotEatsGorilla.hash_to_xml(hash).should == "beergorilla" end it "converts a Hash containing an Array into multiple nodes" do hash = { "apricot" => { "eats" => [ "gorilla", "snake" ] } } ApricotEatsGorilla.hash_to_xml(hash).should == "gorillasnake" end end end