[rspec-users] Comparing two XML documents
Matt Wynne
matt at mattwynne.net
Mon Jan 31 17:16:33 EST 2011
On 31 Jan 2011, at 08:26, Pat Maddox wrote:
> I load my XML docs into a hash using Hash#from_xml and then compare the hashes.
Bullseye! Thanks Pat.
> On Jan 26, 2011, at 7:26 AM, Matt Wynne <matt at mattwynne.net> wrote:
>
>> I have a problem. I have a test that needs to assert that one XML document looks exactly like another XML document.
>>
>> I couldn't find a way to compare them as Nokogiri::XML::Documents, so I converted them both to strings with #to_xml and compared the strings.
>>
>> Trouble is, sometimes the attributes one of the nodes are rendered into the string in a different order to the other one, so you get an error of the form:
>>
>> Diff:
>> @@ -5,7 +5,7 @@
>> <Description/>
>> <Context>
>> <BackgroundLabels>
>> - <Label mode="FILTER" name="included"/>
>> + <Label name="included" mode="FILTER"/>
>> </BackgroundLabels>
>> </Context>
>> <LookAndFeel nonprofit="false"/>
>> (RSpec::Expectations::ExpectationNotMetError)
>>
>> Most annoying.
>>
>> I've seen a couple of RSpec matchers in blog posts that walk and compare XML fragments but I'm surprised there isn't something more concrete that already exists. I feel like I'm missing a way to do it within an XML library, for example.
>>
>> Any clues out there?
>>
>> cheers,
>> Matt
>>
>> matt at mattwynne.net
>> 07974 430184
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
cheers,
Matt
matt at mattwynne.net
07974 430184
More information about the rspec-users
mailing list