equivalent-xml 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -106,7 +106,8 @@ Chained modifiers:
106
106
 
107
107
  ## History
108
108
 
109
- - <b>0.3.0</b> - Added :ignore_content option (conrib. by moklett)
109
+ - <b>0.4.0</b> - Added :ignore_attr_values option (contrib. by ivannovosad)
110
+ - <b>0.3.0</b> - Added :ignore_content option (contrib. by moklett)
110
111
  - <b>0.2.9</b> - Fix for rspec-rails >= 2.7 (contrib. by jcoyne)
111
112
  - <b>0.2.8</b> - Allow comparison against nodesets (contrib. by gkellogg)
112
113
  - <b>0.2.7</b> - Auto-require RSpec matchers if RSpec is loaded
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
  require 'rake/tasklib'
4
- require 'rake/rdoctask'
4
+ require 'rdoc/task'
5
5
 
6
6
  begin
7
7
  Bundler.setup(:default, :development)
@@ -4,7 +4,7 @@ module EquivalentXml
4
4
 
5
5
  class << self
6
6
 
7
- DEFAULT_OPTS = { :element_order => false, :normalize_whitespace => true }
7
+ DEFAULT_OPTS = { :ignore_attr_values => false, :element_order => false, :normalize_whitespace => true }
8
8
 
9
9
  # Determine if two XML documents or nodes are equivalent
10
10
  #
@@ -65,7 +65,14 @@ module EquivalentXml
65
65
  end
66
66
 
67
67
  def compare_attributes(node_1, node_2, opts, &block)
68
- (node_1.name == node_2.name) && (node_1.value == node_2.value)
68
+
69
+ attr_names_match = node_1.name == node_2.name
70
+
71
+ if opts[:ignore_attr_values]
72
+ attr_names_match
73
+ else
74
+ attr_names_match && (node_1.value == node_2.value)
75
+ end
69
76
  end
70
77
 
71
78
  def compare_text(node_1, node_2, opts, &block)
@@ -45,6 +45,10 @@ module EquivalentXml::RSpecMatchers
45
45
  chain :ignoring_content_of do |paths|
46
46
  @opts[:ignore_content] = paths
47
47
  end
48
+
49
+ chain :ignoring_attr_values do
50
+ @opts[:ignore_attr_values] = true
51
+ end
48
52
 
49
53
  failure_message_for_should do |actual|
50
54
  [ 'expected:', expected.to_s, 'got:', actual.to_s ].join("\n")
@@ -207,4 +207,12 @@ describe EquivalentXml do
207
207
  doc1.should be_equivalent_to(doc2).ignoring_content_of(["SerialNumber", "ICCID"])
208
208
  end
209
209
  end
210
+
211
+ context "with :ignore_attr_values set to true" do
212
+ it "ignores the values of attributes when comparing for equivalence" do
213
+ doc1 = Nokogiri::XML("<doc xmlns='foo:bar'><first order='1'>foo bar baz</first><second>things</second></doc>")
214
+ doc2 = Nokogiri::XML("<doc xmlns='foo:bar'><first order='2'>foo bar baz</first><second>things</second></doc>")
215
+ doc1.should be_equivalent_to(doc2).ignoring_attr_values
216
+ end
217
+ end
210
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: equivalent-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: 0.8.7
85
+ version: 0.9.0
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,23 @@ dependencies:
90
90
  requirements:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
- version: 0.8.7
93
+ version: 0.9.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rdoc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '3.12'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '3.12'
94
110
  description: ! "Compares two XML Nodes (Documents, etc.) for certain semantic equivalencies.
95
111
  \n Currently written for Nokogiri, but with an eye toward supporting multiple
96
112
  XML libraries"