test_xml 0.0.4 → 0.1.0
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.
- data/.gitignore +2 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/README.rdoc +56 -73
- data/Rakefile +12 -12
- data/lib/test_xml.rb +0 -2
- data/lib/test_xml/matcher_methods.rb +29 -0
- data/lib/test_xml/mini_test.rb +6 -0
- data/lib/test_xml/nokogiri/node.rb +13 -8
- data/lib/test_xml/spec.rb +1 -4
- data/lib/test_xml/spec/matchers.rb +5 -4
- data/lib/test_xml/spec/matchers/{match_xml.rb → contain_xml.rb} +2 -7
- data/lib/test_xml/spec/matchers/{match_xml_structure.rb → contain_xml_structure.rb} +2 -5
- data/lib/test_xml/spec/matchers/{exactly_match_xml.rb → equal_xml.rb} +2 -7
- data/lib/test_xml/spec/matchers/{exactly_match_xml_structure.rb → equal_xml_structure.rb} +2 -4
- data/lib/test_xml/test_unit.rb +2 -0
- data/lib/test_xml/test_unit/assertions.rb +29 -32
- data/lib/test_xml/version.rb +1 -1
- data/spec/{lib/test_xml/spec/matchers/match_xml_spec.rb → matchers/contain_xml_spec.rb} +5 -5
- data/spec/{lib/test_xml/spec/matchers/match_xml_structure_spec.rb → matchers/contain_xml_structure_spec.rb} +4 -4
- data/spec/{lib/test_xml/spec/matchers/exactly_match_xml_spec.rb → matchers/equal_xml_spec.rb} +6 -4
- data/spec/{lib/test_xml/spec/matchers/exactly_match_xml_structure_spec.rb → matchers/equal_xml_structure_spec.rb} +4 -4
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +1 -4
- data/test/{test_xml/nokogiri → nokogiri}/test_node.rb +14 -7
- data/test/test_helper.rb +1 -4
- data/test/test_unit/test_assertions.rb +227 -0
- data/test_xml.gemspec +28 -0
- metadata +77 -42
- data/test/test_xml/test_unit/test_assertions.rb +0 -159
data/lib/test_xml/version.rb
CHANGED
@@ -12,7 +12,7 @@ describe "match_xml(xml)" do
|
|
12
12
|
|
13
13
|
context "when xml is equal" do
|
14
14
|
it "should pass" do
|
15
|
-
should
|
15
|
+
should contain_xml(<<-XML)
|
16
16
|
<xml>
|
17
17
|
<one>1</one>
|
18
18
|
<two>2</two>
|
@@ -23,7 +23,7 @@ describe "match_xml(xml)" do
|
|
23
23
|
|
24
24
|
context "when xml has less elements" do
|
25
25
|
it "should pass" do
|
26
|
-
should
|
26
|
+
should contain_xml(<<-XML)
|
27
27
|
<xml>
|
28
28
|
<one>1</one>
|
29
29
|
</xml>
|
@@ -33,7 +33,7 @@ describe "match_xml(xml)" do
|
|
33
33
|
|
34
34
|
context "when xml structure is equal but elements have different content" do
|
35
35
|
it "should fail" do
|
36
|
-
should_not
|
36
|
+
should_not contain_xml(<<-XML)
|
37
37
|
<xml>
|
38
38
|
<one>4</one>
|
39
39
|
<two>5</two>
|
@@ -44,7 +44,7 @@ describe "match_xml(xml)" do
|
|
44
44
|
|
45
45
|
context "when xml has more elements" do
|
46
46
|
it "should fail" do
|
47
|
-
should_not
|
47
|
+
should_not contain_xml(<<-XML)
|
48
48
|
<xml>
|
49
49
|
<one>1</one>
|
50
50
|
<two>2</two>
|
@@ -67,7 +67,7 @@ describe "match_xml(xml)" do
|
|
67
67
|
}
|
68
68
|
|
69
69
|
it "should pass" do
|
70
|
-
should
|
70
|
+
should contain_xml(<<-XML)
|
71
71
|
<xml>
|
72
72
|
<errors>
|
73
73
|
<error>one</error>
|
@@ -12,7 +12,7 @@ describe "match_xml_structure(xml)" do
|
|
12
12
|
|
13
13
|
context "when xml is equal" do
|
14
14
|
it "should pass" do
|
15
|
-
should
|
15
|
+
should contain_xml_structure(<<-XML)
|
16
16
|
<xml>
|
17
17
|
<one>1</one>
|
18
18
|
<two>2</two>
|
@@ -23,7 +23,7 @@ describe "match_xml_structure(xml)" do
|
|
23
23
|
|
24
24
|
context "when xml structure is equal but elements have different content" do
|
25
25
|
it "should pass" do
|
26
|
-
should
|
26
|
+
should contain_xml_structure(<<-XML)
|
27
27
|
<xml>
|
28
28
|
<one>4</one>
|
29
29
|
<two>5</two>
|
@@ -34,7 +34,7 @@ describe "match_xml_structure(xml)" do
|
|
34
34
|
|
35
35
|
context "when xml has less elements" do
|
36
36
|
it "should pass" do
|
37
|
-
should
|
37
|
+
should contain_xml_structure(<<-XML)
|
38
38
|
<xml>
|
39
39
|
<one>1</one>
|
40
40
|
</xml>
|
@@ -44,7 +44,7 @@ describe "match_xml_structure(xml)" do
|
|
44
44
|
|
45
45
|
context "when xml has more elements" do
|
46
46
|
it "should fail" do
|
47
|
-
should_not
|
47
|
+
should_not contain_xml_structure(<<-XML)
|
48
48
|
<xml>
|
49
49
|
<one>1</one>
|
50
50
|
<two>2</two>
|
data/spec/{lib/test_xml/spec/matchers/exactly_match_xml_spec.rb → matchers/equal_xml_spec.rb}
RENAMED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# TODO: attributes are not matched.
|
4
|
+
|
3
5
|
describe "exactly_match_xml(xml)" do
|
4
6
|
subject {
|
5
7
|
<<-XML
|
@@ -12,7 +14,7 @@ describe "exactly_match_xml(xml)" do
|
|
12
14
|
|
13
15
|
context "when xml is equal with subject" do
|
14
16
|
it "should pass" do
|
15
|
-
should
|
17
|
+
should equal_xml(<<-XML)
|
16
18
|
<xml>
|
17
19
|
<one>1</one>
|
18
20
|
<two>2</two>
|
@@ -23,7 +25,7 @@ describe "exactly_match_xml(xml)" do
|
|
23
25
|
|
24
26
|
context "when xml structure is equal with subject but elements have different content" do
|
25
27
|
it "should fail" do
|
26
|
-
should_not
|
28
|
+
should_not equal_xml(<<-XML)
|
27
29
|
<xml>
|
28
30
|
<one>4</one>
|
29
31
|
<two>5</two>
|
@@ -34,7 +36,7 @@ describe "exactly_match_xml(xml)" do
|
|
34
36
|
|
35
37
|
context "when xml has less elements" do
|
36
38
|
it "should fail" do
|
37
|
-
should_not
|
39
|
+
should_not equal_xml(<<-XML)
|
38
40
|
<xml>
|
39
41
|
<one>1</one>
|
40
42
|
</xml>
|
@@ -44,7 +46,7 @@ describe "exactly_match_xml(xml)" do
|
|
44
46
|
|
45
47
|
context "when xml has more elements" do
|
46
48
|
it "should fail" do
|
47
|
-
should_not
|
49
|
+
should_not equal_xml(<<-XML)
|
48
50
|
<xml>
|
49
51
|
<one>1</one>
|
50
52
|
<two>2</two>
|
@@ -12,7 +12,7 @@ describe "exactly_match_xml_structure(xml)" do
|
|
12
12
|
|
13
13
|
context "when xml structure is equal with subject" do
|
14
14
|
it "should pass" do
|
15
|
-
should
|
15
|
+
should equal_xml_structure(<<-XML)
|
16
16
|
<xml>
|
17
17
|
<one/>
|
18
18
|
<two/>
|
@@ -23,7 +23,7 @@ describe "exactly_match_xml_structure(xml)" do
|
|
23
23
|
|
24
24
|
context "when xml structure is equal with subject and elements have different content" do
|
25
25
|
it "should pass" do
|
26
|
-
should
|
26
|
+
should equal_xml_structure(<<-XML)
|
27
27
|
<xml>
|
28
28
|
<one>4</one>
|
29
29
|
<two>5</two>
|
@@ -34,7 +34,7 @@ describe "exactly_match_xml_structure(xml)" do
|
|
34
34
|
|
35
35
|
context "when xml has less elements" do
|
36
36
|
it "should fail" do
|
37
|
-
should_not
|
37
|
+
should_not equal_xml_structure(<<-XML)
|
38
38
|
<xml>
|
39
39
|
<one/>
|
40
40
|
</xml>
|
@@ -44,7 +44,7 @@ describe "exactly_match_xml_structure(xml)" do
|
|
44
44
|
|
45
45
|
context "when xml has more elements" do
|
46
46
|
it "should fail" do
|
47
|
-
should_not
|
47
|
+
should_not equal_xml_structure(<<-XML)
|
48
48
|
<xml>
|
49
49
|
<one/>
|
50
50
|
<two/>
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -5,14 +5,14 @@ class TestNode < Test::Unit::TestCase
|
|
5
5
|
assert doc.elements.size == 1
|
6
6
|
assert doc.at('root').elements.size == 2
|
7
7
|
end
|
8
|
-
|
9
|
-
def
|
10
|
-
assert doc(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
XML
|
8
|
+
|
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?
|
15
14
|
end
|
15
|
+
|
16
16
|
|
17
17
|
def test_match_of_elements_without_comparing_values
|
18
18
|
subject = doc(<<-XML)
|
@@ -97,6 +97,13 @@ class TestNode < Test::Unit::TestCase
|
|
97
97
|
assert doc.root.send(:contains_elements_of?, doc.root)
|
98
98
|
assert !doc.root.send(:contains_elements_of?, doc('<root><test_element/></root>'))
|
99
99
|
end
|
100
|
+
|
101
|
+
def test_comparable_attributes
|
102
|
+
assert_equal [["id", "boss"], ["name", "Dude"]], create_element(%{<li name="Dude" id="boss" />}).comparable_attributes
|
103
|
+
|
104
|
+
assert_equal [["name", "Dude"]], create_element(%{<li NAME="Dude"/>}).comparable_attributes
|
105
|
+
end
|
106
|
+
|
100
107
|
|
101
108
|
private
|
102
109
|
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestAssertions < Test::Unit::TestCase
|
4
|
+
def test_assert_xml_contain_message_if_fails
|
5
|
+
begin
|
6
|
+
assert_xml_contain("<root><one>1</one><one>2</one></root>", "<root><one>3</one></root>")
|
7
|
+
rescue Exception => e
|
8
|
+
assert_match %r{the xml:\n<root><one>1</one><one>2</one></root>\nshould contain xml:\n<root><one>3</one></root>}, e.message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_assert_xml_not_contain_message_if_fails
|
13
|
+
begin
|
14
|
+
assert_not_xml_contain("<root><one>1</one><one>2</one></root>", "<root><one>1</one><one>2</one></root>")
|
15
|
+
rescue Exception => e
|
16
|
+
assert_match %r{the xml:\n<root><one>1</one><one>2</one></root>\nshould not contain xml:\n<root><one>1</one><one>2</one></root> but it does},
|
17
|
+
e.message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_assert_xml_contain
|
22
|
+
expected = <<-XML
|
23
|
+
<root>
|
24
|
+
<one id="first">1</one>
|
25
|
+
<two>2</two>
|
26
|
+
</root>
|
27
|
+
XML
|
28
|
+
|
29
|
+
actual = <<-XML
|
30
|
+
<root>
|
31
|
+
<one id="first">1</one>
|
32
|
+
</root>
|
33
|
+
XML
|
34
|
+
|
35
|
+
assert_xml_contain expected, actual
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_assert_not_xml_contain
|
39
|
+
expected = <<-XML
|
40
|
+
<root>
|
41
|
+
<one>1</one>
|
42
|
+
</root>
|
43
|
+
XML
|
44
|
+
|
45
|
+
actual = <<-XML
|
46
|
+
<root>
|
47
|
+
<one>2</one>
|
48
|
+
</root>
|
49
|
+
XML
|
50
|
+
|
51
|
+
assert_not_xml_contain expected, actual
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_assert_xml_structure_contain
|
55
|
+
expected = <<-XML
|
56
|
+
<root>
|
57
|
+
<one>1</one>
|
58
|
+
<two>
|
59
|
+
<three>3</three>
|
60
|
+
</two>
|
61
|
+
</root>
|
62
|
+
XML
|
63
|
+
|
64
|
+
actual = <<-XML
|
65
|
+
<root>
|
66
|
+
<one>2</one>
|
67
|
+
<two>
|
68
|
+
<three>4</three>
|
69
|
+
</two>
|
70
|
+
</root>
|
71
|
+
XML
|
72
|
+
|
73
|
+
assert_xml_structure_contain expected, actual
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_assert_not_xml_structure_contain
|
77
|
+
expected = <<-XML
|
78
|
+
<root>
|
79
|
+
<one>1</one>
|
80
|
+
<two>
|
81
|
+
<three>3</three>
|
82
|
+
</two>
|
83
|
+
</root>
|
84
|
+
XML
|
85
|
+
|
86
|
+
actual = <<-XML
|
87
|
+
<root>
|
88
|
+
<one>2</one>
|
89
|
+
<two>
|
90
|
+
<four/>
|
91
|
+
</two>
|
92
|
+
</root>
|
93
|
+
XML
|
94
|
+
|
95
|
+
assert_not_xml_structure_contain expected, actual
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_assert_xml_equal
|
99
|
+
expected = <<-XML
|
100
|
+
<root>
|
101
|
+
<one>1</one>
|
102
|
+
<two>2</two>
|
103
|
+
</root>
|
104
|
+
XML
|
105
|
+
|
106
|
+
actual = <<-XML
|
107
|
+
<root>
|
108
|
+
<one>1</one>
|
109
|
+
<two>2</two>
|
110
|
+
</root>
|
111
|
+
XML
|
112
|
+
|
113
|
+
assert_xml_equal expected, actual
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_assert_xml_equal_with_attributes
|
117
|
+
expected = <<-XML
|
118
|
+
<root>
|
119
|
+
<one b="second" a="first">1</one>
|
120
|
+
<two b="second" a="first" />
|
121
|
+
</root>
|
122
|
+
XML
|
123
|
+
|
124
|
+
actual = <<-XML
|
125
|
+
<root>
|
126
|
+
<one a="first" b="second">1</one>
|
127
|
+
<two b="second" a="first" />
|
128
|
+
</root>
|
129
|
+
XML
|
130
|
+
|
131
|
+
assert_xml_equal expected, actual
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_assert_not_xml_equal_with_attributes
|
135
|
+
expected = <<-XML
|
136
|
+
<root>
|
137
|
+
<one b="second" a="first">1</one>
|
138
|
+
</root>
|
139
|
+
XML
|
140
|
+
|
141
|
+
actual = <<-XML
|
142
|
+
<root>
|
143
|
+
<one a="whoops, wrong" b="second">1</one>
|
144
|
+
</root>
|
145
|
+
XML
|
146
|
+
|
147
|
+
assert_not_xml_equal expected, actual
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_assert_not_xml_equal_with_attributes_and_no_text
|
151
|
+
expected = <<-XML
|
152
|
+
<root>
|
153
|
+
<one b="second" a="first" />
|
154
|
+
</root>
|
155
|
+
XML
|
156
|
+
|
157
|
+
actual = <<-XML
|
158
|
+
<root>
|
159
|
+
<one a="whoops, wrong" b="second" />
|
160
|
+
</root>
|
161
|
+
XML
|
162
|
+
|
163
|
+
assert_not_xml_equal expected, actual
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_assert_not_xml_equal
|
167
|
+
expected = <<-XML
|
168
|
+
<root>
|
169
|
+
<one>1</one>
|
170
|
+
<two>2</two>
|
171
|
+
</root>
|
172
|
+
XML
|
173
|
+
|
174
|
+
actual = <<-XML
|
175
|
+
<root>
|
176
|
+
<one>1</one>
|
177
|
+
</root>
|
178
|
+
XML
|
179
|
+
|
180
|
+
assert_not_xml_equal expected, actual
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_assert_xml_structure_equal
|
184
|
+
expected = <<-XML
|
185
|
+
<root>
|
186
|
+
<one>1</one>
|
187
|
+
<two>
|
188
|
+
<three>3</three>
|
189
|
+
</two>
|
190
|
+
</root>
|
191
|
+
XML
|
192
|
+
|
193
|
+
actual = <<-XML
|
194
|
+
<root>
|
195
|
+
<one>2</one>
|
196
|
+
<two>
|
197
|
+
<three>4</three>
|
198
|
+
</two>
|
199
|
+
</root>
|
200
|
+
XML
|
201
|
+
|
202
|
+
assert_xml_structure_equal expected, actual
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_assert_not_xml_structure_equal
|
206
|
+
expected = <<-XML
|
207
|
+
<root>
|
208
|
+
<one>1</one>
|
209
|
+
<two>
|
210
|
+
<three>3</three>
|
211
|
+
</two>
|
212
|
+
</root>
|
213
|
+
XML
|
214
|
+
|
215
|
+
actual = <<-XML
|
216
|
+
<root>
|
217
|
+
<one>2</one>
|
218
|
+
<two>
|
219
|
+
<three>3</three>
|
220
|
+
<four/>
|
221
|
+
</two>
|
222
|
+
</root>
|
223
|
+
XML
|
224
|
+
|
225
|
+
assert_not_xml_structure_equal expected, actual
|
226
|
+
end
|
227
|
+
end
|
data/test_xml.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'test_xml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "test_xml"
|
8
|
+
s.version = TestXml::VERSION
|
9
|
+
s.authors = ["Pavel Gabriel", "Nick Sutterer"]
|
10
|
+
s.homepage = "http://github.com/alovak/test_xml"
|
11
|
+
s.summary = "Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber."
|
12
|
+
s.description = "Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber using handy assertions like #assert_xml_equal or #assert_xml_structure_contain."
|
13
|
+
s.email = ["alovak@gmail.com", "apotonick@gmail.com"]
|
14
|
+
s.require_path = "lib"
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.extra_rdoc_files = ['README.rdoc']
|
17
|
+
s.rdoc_options = ['--main', 'README.rdoc']
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
|
22
|
+
s.rubygems_version = "1.3.5"
|
23
|
+
s.add_dependency("nokogiri", [">= 1.3.2"])
|
24
|
+
|
25
|
+
s.add_development_dependency("rake")
|
26
|
+
s.add_development_dependency("rdoc")
|
27
|
+
s.add_development_dependency("rspec-core", ["~> 2.2"])
|
28
|
+
end
|