Forum: RSpec Comparing two XML documents

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2011-01-26 16:33
(Received via mailing list)
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:

    @@ -5,7 +5,7 @@
    -        <Label mode="FILTER" name="included"/>
    +        <Label name="included" mode="FILTER"/>
        <LookAndFeel nonprofit="false"/>

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?

07974 430184
Kam Dahlin (Guest)
on 2011-01-26 22:03
(Received via mailing list)
Aaron Patterson (author of Nokogiri) addressed this issue directly here:
I don't think document comparison was ever implemented in Nokogiri


Pat Maddox (Guest)
on 2011-01-31 09:56
(Received via mailing list)
I load my XML docs into a hash using Hash#from_xml and then compare the
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2011-01-31 23:56
(Received via mailing list)
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.

>>       <Description/>
>> _______________________________________________
>> rspec-users mailing list
> _______________________________________________
> rspec-users mailing list

07974 430184
This topic is locked and can not be replied to.