test_xml 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test_xml (0.0.4)
4
+ test_xml (0.1.1)
5
5
  nokogiri (>= 1.3.2)
6
6
 
7
7
  GEM
@@ -23,7 +23,7 @@ module TestXml
23
23
 
24
24
  private
25
25
  def self.parse_xml(subject, pattern)
26
- [Nokogiri::XML.parse(subject), Nokogiri::XML.parse(pattern)]
26
+ [Nokogiri::XML.parse(subject).root, Nokogiri::XML.parse(pattern).root]
27
27
  end
28
28
  end
29
29
  end
@@ -5,8 +5,16 @@ module TestXml
5
5
  if compare_value && element.leaf?
6
6
  comparable_attributes == element.comparable_attributes and equal_text?(element)
7
7
  else
8
- contains_elements_of?(element) &&
9
- element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
8
+
9
+ #TODO clean this part of the code
10
+ if compare_value
11
+ (comparable_attributes == element.comparable_attributes) &&
12
+ contains_elements_of?(element) &&
13
+ element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
14
+ else
15
+ contains_elements_of?(element) &&
16
+ element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
17
+ end
10
18
  end
11
19
  end
12
20
 
@@ -1,3 +1,3 @@
1
1
  module TestXml
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -30,6 +30,39 @@ describe "equal_xml(xml)" do
30
30
  end
31
31
  end
32
32
 
33
+ context "when subject has elements with attributes" do
34
+ subject {
35
+ <<-XML
36
+ <xml test="true">
37
+ <one type="text" attr="hello">1</one>
38
+ <two type="integer">2</two>
39
+ </xml>
40
+ XML
41
+ }
42
+
43
+ context "and xml has similar elements with attributes" do
44
+ it "should pass" do
45
+ should equal_xml(<<-XML)
46
+ <xml test="true">
47
+ <one type="text" attr="hello">1</one>
48
+ <two type="integer">2</two>
49
+ </xml>
50
+ XML
51
+ end
52
+ end
53
+
54
+ context "and xml has elements with different attributes" do
55
+ it "should fail" do
56
+ should_not equal_xml(<<-XML)
57
+ <xml>
58
+ <one type="text" attr="hello">1</one>
59
+ <two type="integer">2</two>
60
+ </xml>
61
+ XML
62
+ end
63
+ end
64
+ end
65
+
33
66
  context "when xml is equal with subject" do
34
67
  it "should pass" do
35
68
  should equal_xml(<<-XML)
@@ -7,15 +7,15 @@ class TestNode < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_leaf?
10
- assert doc("<a/>").root.leaf?
11
- assert doc("<a>Yo</a>").root.leaf?
12
- assert doc("<a></a>").root.leaf?
13
- assert !doc("<div><a/></div>").root.leaf?
10
+ assert root("<a/>").leaf?
11
+ assert root("<a>Yo</a>").leaf?
12
+ assert root("<a></a>").leaf?
13
+ assert !root("<div><a/></div>").leaf?
14
14
  end
15
15
 
16
16
 
17
17
  def test_match_of_elements_without_comparing_values
18
- subject = doc(<<-XML)
18
+ subject = root(<<-XML)
19
19
  <root>
20
20
  <one>1</one>
21
21
  <two>
@@ -24,7 +24,7 @@ class TestNode < Test::Unit::TestCase
24
24
  </root>
25
25
  XML
26
26
 
27
- pattern = doc(<<-XML)
27
+ pattern = root(<<-XML)
28
28
  <root>
29
29
  <two><three/></two>
30
30
  <one>2</one>
@@ -35,14 +35,14 @@ class TestNode < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_no_match_of_elements_without_comparing_values
38
- subject = doc(<<-XML)
38
+ subject = root(<<-XML)
39
39
  <root>
40
40
  <one>1</one>
41
41
  <two/>
42
42
  </root>
43
43
  XML
44
44
 
45
- pattern = doc(<<-XML)
45
+ pattern = root(<<-XML)
46
46
  <root>
47
47
  <four/>
48
48
  <five>5</five>
@@ -53,14 +53,14 @@ class TestNode < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_match_with_values
56
- subject = doc(<<-XML)
56
+ subject = root(<<-XML)
57
57
  <root>
58
58
  <one>1</one>
59
59
  <two><three>3</three></two>
60
60
  </root>
61
61
  XML
62
62
 
63
- pattern = doc(<<-XML)
63
+ pattern = root(<<-XML)
64
64
  <root>
65
65
  <two><three>3</three></two>
66
66
  <one>1</one>
@@ -71,13 +71,13 @@ class TestNode < Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def test_no_match_with_values
74
- subject = doc(<<-XML)
74
+ subject = root(<<-XML)
75
75
  <root>
76
76
  <one>1</one>
77
77
  </root>
78
78
  XML
79
79
 
80
- not_matched_pattern = doc(<<-XML)
80
+ not_matched_pattern = root(<<-XML)
81
81
  <root>
82
82
  <one>2</one>
83
83
  </root>
@@ -111,6 +111,10 @@ class TestNode < Test::Unit::TestCase
111
111
  Nokogiri::XML::Document.parse(xml).root
112
112
  end
113
113
 
114
+ def root(xml)
115
+ doc(xml).root
116
+ end
117
+
114
118
  def doc(xml = nil)
115
119
  xml ||= <<-XML
116
120
  <root>
@@ -130,6 +130,24 @@ class TestAssertions < Test::Unit::TestCase
130
130
 
131
131
  assert_xml_equal expected, actual
132
132
  end
133
+
134
+ def test_assert_xml_equal_with_attributes_in_branch_element
135
+ expected = <<-XML
136
+ <root type="test">
137
+ <one>1</one>
138
+ <two/>
139
+ </root>
140
+ XML
141
+
142
+ actual = <<-XML
143
+ <root type="test">
144
+ <one>1</one>
145
+ <two/>
146
+ </root>
147
+ XML
148
+
149
+ assert_xml_equal expected, actual
150
+ end
133
151
 
134
152
  def test_assert_not_xml_equal_with_attributes
135
153
  expected = <<-XML
@@ -146,6 +164,7 @@ class TestAssertions < Test::Unit::TestCase
146
164
 
147
165
  assert_not_xml_equal expected, actual
148
166
  end
167
+
149
168
 
150
169
  def test_assert_not_xml_equal_with_attributes_and_no_text
151
170
  expected = <<-XML
@@ -163,6 +182,24 @@ class TestAssertions < Test::Unit::TestCase
163
182
  assert_not_xml_equal expected, actual
164
183
  end
165
184
 
185
+ def test_assert_not_xml_equal_with_attributes_in_branch_element
186
+ expected = <<-XML
187
+ <root type="test">
188
+ <one>1</one>
189
+ <two/>
190
+ </root>
191
+ XML
192
+
193
+ actual = <<-XML
194
+ <root>
195
+ <one>1</one>
196
+ <two/>
197
+ </root>
198
+ XML
199
+
200
+ assert_not_xml_equal expected, actual
201
+ end
202
+
166
203
  def test_assert_not_xml_equal
167
204
  expected = <<-XML
168
205
  <root>
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_xml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
5
+ version: 0.1.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Pavel Gabriel
@@ -16,7 +11,7 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2011-04-15 00:00:00 +03:00
14
+ date: 2011-04-21 00:00:00 +03:00
20
15
  default_executable:
21
16
  dependencies:
22
17
  - !ruby/object:Gem::Dependency
@@ -27,11 +22,6 @@ dependencies:
27
22
  requirements:
28
23
  - - ">="
29
24
  - !ruby/object:Gem::Version
30
- hash: 31
31
- segments:
32
- - 1
33
- - 3
34
- - 2
35
25
  version: 1.3.2
36
26
  type: :runtime
37
27
  version_requirements: *id001
@@ -43,9 +33,6 @@ dependencies:
43
33
  requirements:
44
34
  - - ">="
45
35
  - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
36
  version: "0"
50
37
  type: :development
51
38
  version_requirements: *id002
@@ -57,9 +44,6 @@ dependencies:
57
44
  requirements:
58
45
  - - ">="
59
46
  - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
47
  version: "0"
64
48
  type: :development
65
49
  version_requirements: *id003
@@ -71,10 +55,6 @@ dependencies:
71
55
  requirements:
72
56
  - - ~>
73
57
  - !ruby/object:Gem::Version
74
- hash: 7
75
- segments:
76
- - 2
77
- - 2
78
58
  version: "2.2"
79
59
  type: :development
80
60
  version_requirements: *id004
@@ -132,18 +112,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
112
  requirements:
133
113
  - - ">="
134
114
  - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
115
  version: "0"
139
116
  required_rubygems_version: !ruby/object:Gem::Requirement
140
117
  none: false
141
118
  requirements:
142
119
  - - ">="
143
120
  - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
121
  version: "0"
148
122
  requirements: []
149
123