test/xml_test.rb in crack-0.1.2 vs test/xml_test.rb in crack-0.1.3

- old
+ new

@@ -63,11 +63,42 @@ 'login' => 'grep', 'fullname' => 'Gary R Epstein' } } } - + Crack::XML.parse(xml).should == hash + end + + context "Parsing xml with text and attributes" do + setup do + xml =<<-XML + <opt> + <user login="grep">Gary R Epstein</user> + <user>Simon T Tyson</user> + </opt> + XML + @data = Crack::XML.parse(xml) + end + + should "correctly parse text nodes" do + @data.should == { + 'opt' => { + 'user' => [ + 'Gary R Epstein', + 'Simon T Tyson' + ] + } + } + end + + should "be parse attributes for text node if present" do + @data['opt']['user'][0].attributes.should == {'login' => 'grep'} + end + + should "default attributes to empty hash if not present" do + @data['opt']['user'][1].attributes.should == {} + end end should "should typecast an integer" do xml = "<tag type='integer'>10</tag>" Crack::XML.parse(xml)['tag'].should == 10 \ No newline at end of file