vkononov / compare-xml

CompareXML is a fast, lightweight and feature-rich tool that will solve your XML/HTML comparison or diffing needs. its purpose is to compare two instances of Nokogiri::XML::Node or Nokogiri::XML::NodeSet for equality or equivalency.
MIT License
12 stars 3 forks source link

Ignoring attributes works in unexpected ways #4

Open triskweline opened 3 years ago

triskweline commented 3 years ago

Thank you for this gem! I found it to be super helpful in tests.

One thing that was really unexpected for me is that options to ignore attributes require the attribute to be present in both elements.

For example, with ignore_attrs_by_name: ['class'] I expected the following two elements to be equivalent:

<div class="foo"></div>
<div></div>

However, they are considered to be different.

For them to be equivalent the second element must have a [class] attribute, with any value:

<div class="foo"></div>
<div class></div>

Maybe this is something that could be changed or documented.

Thanks again for the gem!

anitagraham commented 2 years ago

I've just found the same same thing, which is impeding some tests.

Using either ignore_attrs_by_name: ["media"], or ignore_attrs: ['[media]'], a fragment with a media attribute is considered different from one without a media atttribute.

Would it be possible to have yet_another_option such as :ignore_nil_attributes?

Note: a change in Rails 7: ActionView config.apply_stylesheet_media_default is causing the changes in the markup being compared.

thanks