Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add option :ignore_attr_values in equivalence checks #12

Merged
merged 3 commits into from

2 participants

@ivannovosad

No description provided.

@mbklein mbklein merged commit 5824f45 into mbklein:master

1 check failed

Details default The Travis CI build could not complete due to an error
@ivannovosad

Thank you

@mbklein
Owner

Sure thing. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  equivalent-xml.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{equivalent-xml}
- s.version = "0.3.0"
+ s.version = "0.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael B. Klein"]
View
11 lib/equivalent-xml.rb
@@ -4,7 +4,7 @@ module EquivalentXml
class << self
- DEFAULT_OPTS = { :element_order => false, :normalize_whitespace => true }
+ DEFAULT_OPTS = { :ignore_attr_values => false, :element_order => false, :normalize_whitespace => true }
# Determine if two XML documents or nodes are equivalent
#
@@ -65,7 +65,14 @@ def compare_elements(node_1, node_2, opts, &block)
end
def compare_attributes(node_1, node_2, opts, &block)
- (node_1.name == node_2.name) && (node_1.value == node_2.value)
+
+ attr_names_match = node_1.name == node_2.name
+
+ if opts[:ignore_attr_values]
+ attr_names_match
+ else
+ attr_names_match && (node_1.value == node_2.value)
+ end
end
def compare_text(node_1, node_2, opts, &block)
View
4 lib/equivalent-xml/rspec_matchers.rb
@@ -45,6 +45,10 @@ def be_equivalent_to(expected)
chain :ignoring_content_of do |paths|
@opts[:ignore_content] = paths
end
+
+ chain :ignoring_attr_values do
+ @opts[:ignore_attr_values] = true
+ end
failure_message_for_should do |actual|
[ 'expected:', expected.to_s, 'got:', actual.to_s ].join("\n")
View
8 spec/equivalent-xml_spec.rb
@@ -207,4 +207,12 @@
doc1.should be_equivalent_to(doc2).ignoring_content_of(["SerialNumber", "ICCID"])
end
end
+
+ context "with :ignore_attr_values set to true" do
+ it "ignores the values of attributes when comparing for equivalence" do
+ doc1 = Nokogiri::XML("<doc xmlns='foo:bar'><first order='1'>foo bar baz</first><second>things</second></doc>")
+ doc2 = Nokogiri::XML("<doc xmlns='foo:bar'><first order='2'>foo bar baz</first><second>things</second></doc>")
+ doc1.should be_equivalent_to(doc2).ignoring_attr_values
+ end
+ end
end
Something went wrong with that request. Please try again.