Permalink
Browse files

Add option :ignore_attr_values in equivalence checks

  • Loading branch information...
1 parent a33047e commit d444c6aafa1976d42a99de31f6f06ba3624b68ae @ivannovosad committed Dec 11, 2013
Showing with 13 additions and 2 deletions.
  1. +9 −2 lib/equivalent-xml.rb
  2. +4 −0 lib/equivalent-xml/rspec_matchers.rb
View
@@ -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)
@@ -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")

0 comments on commit d444c6a

Please sign in to comment.