mbklein / equivalent-xml

Easy equivalency tests for Nokogiri and Oga XML
MIT License
94 stars 29 forks source link

Provides option to :ignore_content in equivalence checks #7

Closed moklett closed 12 years ago

moklett commented 12 years ago

Using the :ignore_content option, you may provide one or more CSS selectors of nodes for which the content should be ignored when checking for equivalence.

For example, consider my list of devices and Sally's:

Mine:

    <Devices>
      <Device>
        <Name>iPhone</Name>
        <ModelNumber>5</ModelNumber>
        <SerialNumber>1234</SerialNumber>
      </Device>
    </Devices>

Sally's:

    <Devices>
      <Device>
        <Name>iPhone</Name>
        <ModelNumber>5</ModelNumber>
        <SerialNumber>5678</SerialNumber>
      </Device>
    </Devices>

By ignoring the SerialNumber, I am able to determine that we have the same list of devices, since for this purpose I don't care about a match on the SerialNumber.

EquivalentXml.equivalent?(mine, sallys)
# => false

EquivalentXml.equivalent?(mine, sallys, :ignore_content => "SerialNumber")
# => true

# Rspec
mine.should be_equivalent_to(sallys).ignoring_content_of("SerialNumber")

I'm pretty happy with the functionality of this, but I'm open to better suggestions for the option name... what do you think?

mbklein commented 12 years ago

This looks great! Thanks for contributing. I'll merge and release sometime in the next couple days.