From an XML point of view documents with different child ordering are
not equivalent. So you will not be likely to find standard XML tools
that do the comparison - at least not without further adjusting (e.g.
ordering elements before feeding them to the comparison or converting
them to something else as were suggested.
require 'active_support'
require 'active_support/xml_mini'
require 'active_support/core_ext/hash'
doc1 = Hash.from_xml<<END
<foo>
<bar>1</bar>
<bar>2</bar>
</foo>
END
doc2 = Hash.from_xml<<END
<foo>
<bar>1</bar>
<bar>2</bar>
</foo>
END
# assert_equal doc1, doc2
#=> pass
doc3 = Hash.from_xml<<END
<foo>
<bar>2</bar>
<bar>1</bar>
</foo>
END
# assert_equal doc1, doc3
#=> fail
def foo thing
case thing
when Hash
thing.each{|_, t| foo t}
when Array
thing.sort!
thing.each{|t| foo t}
I would rather use
thing.sort.each{|t| foo t}
to avoid side effects from the test. Tests are generally considered
read only and if they have side effects you'll run into weird issues
that will be hard to hunt down.
end
end
# assert_equal doc1, foo(doc3)
#=> true
Kind regards
robert