rspec-html-matchers 0.8.1 → 0.9.4
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +45 -12
- data/README.md +13 -18
- data/features/step_definitions/steps.rb +3 -1
- data/features/support/env.rb +22 -3
- data/lib/rspec-html-matchers.rb +160 -356
- data/lib/rspec-html-matchers/have_tag.rb +290 -0
- data/lib/rspec-html-matchers/nokogiri_regexp_helper.rb +17 -0
- data/lib/rspec-html-matchers/nokogiri_text_helper.rb +24 -0
- data/lib/rspec-html-matchers/version.rb +5 -0
- data/spec/form_matchers_spec.rb +132 -130
- data/spec/have_empty_tag_spec.rb +9 -7
- data/spec/have_tag_spec.rb +270 -166
- data/spec/issues_spec.rb +17 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/asset_helpers.rb +5 -5
- data/spec/support/raise_spec_error_helper.rb +9 -7
- metadata +58 -25
data/spec/have_empty_tag_spec.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
describe 'have_empty_tag' do
|
5
|
-
context '
|
7
|
+
context '[single element]' do
|
6
8
|
asset 'single_element'
|
7
9
|
|
8
10
|
it { expect(rendered).to have_empty_tag('div') }
|
9
|
-
it { expect(rendered).to have_empty_tag('div', class
|
10
|
-
it { expect(rendered).to have_empty_tag('div', class
|
11
|
-
it { expect(rendered).to have_empty_tag('div', class
|
11
|
+
it { expect(rendered).to have_empty_tag('div', :class => 'foo') }
|
12
|
+
it { expect(rendered).to have_empty_tag('div', :class => 'bar') }
|
13
|
+
it { expect(rendered).to have_empty_tag('div', :class => 'foo bar') }
|
12
14
|
end
|
13
15
|
|
14
|
-
context '
|
16
|
+
context '[paragraphs]' do
|
15
17
|
asset 'paragraphs'
|
16
18
|
|
17
19
|
it { expect(rendered).to_not have_empty_tag('p') }
|
18
20
|
end
|
19
21
|
|
20
|
-
context '
|
22
|
+
context '[ordered list]' do
|
21
23
|
asset 'ordered_list'
|
22
24
|
|
23
25
|
it { expect(rendered).to_not have_empty_tag('html') }
|
24
26
|
it { expect(rendered).to_not have_empty_tag('body') }
|
25
27
|
it { expect(rendered).to_not have_empty_tag('ol') }
|
26
|
-
it { expect(rendered).to_not have_empty_tag('ol', class
|
28
|
+
it { expect(rendered).to_not have_empty_tag('ol', :class => 'menu') }
|
27
29
|
it { expect(rendered).to_not have_empty_tag('li') }
|
28
30
|
end
|
29
31
|
end
|
data/spec/have_tag_spec.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
# encoding:
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
describe 'have_tag' do
|
5
|
-
context
|
7
|
+
context '[through css selector]' do
|
6
8
|
asset 'search_and_submit'
|
7
9
|
|
8
|
-
it
|
10
|
+
it 'should have right description' do
|
9
11
|
expect(have_tag('div').description).to eq 'have at least 1 element matching "div"'
|
10
12
|
expect(have_tag('div.class').description).to eq 'have at least 1 element matching "div.class"'
|
11
13
|
expect(have_tag('div#id').description).to eq 'have at least 1 element matching "div#id"'
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
16
|
+
it 'should find tags' do
|
15
17
|
expect(rendered).to have_tag('div')
|
16
18
|
expect(rendered).to have_tag(:div)
|
17
19
|
expect(rendered).to have_tag('div#div')
|
@@ -19,7 +21,7 @@ describe 'have_tag' do
|
|
19
21
|
expect(rendered).to have_tag('div p strong')
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
24
|
+
it 'should not find tags' do
|
23
25
|
expect(rendered).to_not have_tag('span')
|
24
26
|
expect(rendered).to_not have_tag(:span)
|
25
27
|
expect(rendered).to_not have_tag('span#id')
|
@@ -27,134 +29,133 @@ describe 'have_tag' do
|
|
27
29
|
expect(rendered).to_not have_tag('div div span')
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it 'should not find tags and display appropriate message' do
|
31
33
|
expect {
|
32
34
|
expect(rendered).to have_tag('span')
|
33
35
|
}.to raise_spec_error(
|
34
|
-
%
|
36
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "span", found 0.)
|
35
37
|
)
|
36
38
|
expect {
|
37
39
|
expect(rendered).to have_tag('span#some_id')
|
38
40
|
}.to raise_spec_error(
|
39
|
-
%
|
41
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "span#some_id", found 0.)
|
40
42
|
)
|
41
43
|
expect {
|
42
44
|
expect(rendered).to have_tag('span.some_class')
|
43
45
|
}.to raise_spec_error(
|
44
|
-
%
|
46
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "span.some_class", found 0.)
|
45
47
|
)
|
46
48
|
end
|
47
49
|
|
48
|
-
it
|
50
|
+
it 'should find unexpected tags and display appropriate message' do
|
49
51
|
expect {
|
50
52
|
expect(rendered).to_not have_tag('div')
|
51
53
|
}.to raise_spec_error(
|
52
|
-
%
|
54
|
+
%(expected following:\n#{rendered}\nto NOT have element matching "div", found 2.)
|
53
55
|
)
|
54
56
|
expect {
|
55
57
|
expect(rendered).to_not have_tag('div#div')
|
56
58
|
}.to raise_spec_error(
|
57
|
-
%
|
59
|
+
%(expected following:\n#{rendered}\nto NOT have element matching "div#div", found 1.)
|
58
60
|
)
|
59
61
|
expect {
|
60
62
|
expect(rendered).to_not have_tag('p.paragraph')
|
61
63
|
}.to raise_spec_error(
|
62
|
-
%
|
64
|
+
%(expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.)
|
63
65
|
)
|
64
66
|
end
|
65
67
|
|
66
|
-
context
|
67
|
-
it
|
68
|
-
expect(rendered).to have_tag('input#search'
|
69
|
-
expect(rendered).to have_tag(:input
|
68
|
+
context '[with additional HTML attributes(:with option)]' do
|
69
|
+
it 'should find tags' do
|
70
|
+
expect(rendered).to have_tag('input#search', :with => { :type => 'text' })
|
71
|
+
expect(rendered).to have_tag(:input, :with => { :type => 'submit', :value => 'Save' })
|
70
72
|
end
|
71
73
|
|
72
|
-
it
|
73
|
-
expect(rendered).to have_tag('div'
|
74
|
-
expect(rendered).to have_tag('div'
|
74
|
+
it 'should find tags that have classes specified via array(or string)' do
|
75
|
+
expect(rendered).to have_tag('div', :with => { :class => %w[class-one class-two] })
|
76
|
+
expect(rendered).to have_tag('div', :with => { :class => 'class-two class-one' })
|
75
77
|
end
|
76
78
|
|
77
|
-
it
|
78
|
-
expect(rendered).to_not have_tag('div'
|
79
|
+
it 'should not find tags that have classes specified via array' do
|
80
|
+
expect(rendered).to_not have_tag('div', :with => { :class => %w[class-other class-two] })
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
83
|
+
it 'should not find tags that have classes specified via array and display appropriate message' do
|
82
84
|
expect {
|
83
|
-
expect(rendered).to have_tag('div'
|
85
|
+
expect(rendered).to have_tag('div', :with => { :class => %w[class-other class-two] })
|
84
86
|
}.to raise_spec_error(
|
85
|
-
%
|
87
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.)
|
86
88
|
)
|
87
89
|
expect {
|
88
|
-
expect(rendered).to have_tag('div'
|
90
|
+
expect(rendered).to have_tag('div', :with => { :class => 'class-other class-two' })
|
89
91
|
}.to raise_spec_error(
|
90
|
-
%
|
92
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.)
|
91
93
|
)
|
92
94
|
end
|
93
95
|
|
94
|
-
it
|
95
|
-
expect(rendered).to_not have_tag('input#search'
|
96
|
-
expect(rendered).to_not have_tag(:input, :with => {:type =>
|
96
|
+
it 'should not find tags' do
|
97
|
+
expect(rendered).to_not have_tag('input#search', :with => { :type => 'some_other_type' })
|
98
|
+
expect(rendered).to_not have_tag(:input, :with => { :type => 'some_other_type' })
|
97
99
|
end
|
98
100
|
|
99
|
-
it
|
101
|
+
it 'should not find tags and display appropriate message' do
|
100
102
|
expect {
|
101
|
-
expect(rendered).to have_tag('input#search'
|
103
|
+
expect(rendered).to have_tag('input#search', :with => { :type => 'some_other_type' })
|
102
104
|
}.to raise_spec_error(
|
103
|
-
%
|
105
|
+
%(expected following:\n#{rendered}\nto have at least 1 element matching "input#search[type='some_other_type']", found 0.)
|
104
106
|
)
|
105
107
|
end
|
106
108
|
|
107
|
-
it
|
109
|
+
it 'should find unexpected tags and display appropriate message' do
|
108
110
|
expect {
|
109
|
-
expect(rendered).to_not have_tag('input#search'
|
111
|
+
expect(rendered).to_not have_tag('input#search', :with => { :type => 'text' })
|
110
112
|
}.to raise_spec_error(
|
111
|
-
%
|
113
|
+
%(expected following:\n#{rendered}\nto NOT have element matching "input#search[type='text']", found 1.)
|
112
114
|
)
|
113
115
|
end
|
114
|
-
|
115
116
|
end
|
116
117
|
|
117
|
-
context
|
118
|
+
context '[with additional HTML attributes (:without option)]' do
|
118
119
|
asset 'single_element'
|
119
120
|
|
120
|
-
it
|
121
|
-
expect(rendered).to_not have_tag('div', :without => { :class => %w
|
121
|
+
it 'should find tags that have classes specified via array (or string)' do
|
122
|
+
expect(rendered).to_not have_tag('div', :without => { :class => %w[foo bar] })
|
122
123
|
expect(rendered).to_not have_tag('div', :without => { :class => 'foo bar' })
|
123
124
|
expect(rendered).to_not have_tag('div', :without => { :class => 'foo' })
|
124
125
|
expect(rendered).to_not have_tag('div', :without => { :class => 'bar' })
|
125
126
|
end
|
126
127
|
|
127
|
-
it
|
128
|
-
expect(rendered).to have_tag('div', :without => { :class => %w
|
128
|
+
it 'should not find tags that have classes specified via array (or string)' do
|
129
|
+
expect(rendered).to have_tag('div', :without => { :class => %w[foo baz] })
|
129
130
|
expect(rendered).to have_tag('div', :without => { :class => 'foo baz' })
|
130
131
|
expect(rendered).to have_tag('div', :without => { :class => 'baz' })
|
131
132
|
end
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
|
-
context
|
136
|
+
context '[by count]' do
|
136
137
|
asset 'paragraphs'
|
137
138
|
|
138
|
-
it
|
139
|
+
it 'should have right description' do
|
139
140
|
expect(have_tag('div', :count => 100500).description).to eq 'have 100500 element(s) matching "div"'
|
140
141
|
end
|
141
142
|
|
142
|
-
it
|
143
|
+
it 'should find tags' do
|
143
144
|
expect(rendered).to have_tag('p', :count => 3)
|
144
145
|
expect(rendered).to have_tag('p', :count => 2..3)
|
145
146
|
end
|
146
147
|
|
147
|
-
it
|
148
|
+
it 'should find tags when :minimum specified' do
|
148
149
|
expect(rendered).to have_tag('p', :min => 3)
|
149
150
|
expect(rendered).to have_tag('p', :minimum => 2)
|
150
151
|
end
|
151
152
|
|
152
|
-
it
|
153
|
+
it 'should find tags when :maximum specified' do
|
153
154
|
expect(rendered).to have_tag('p', :max => 4)
|
154
155
|
expect(rendered).to have_tag('p', :maximum => 3)
|
155
156
|
end
|
156
157
|
|
157
|
-
it
|
158
|
+
it 'should not find tags(with :count, :minimum or :maximum specified)' do
|
158
159
|
expect(rendered).to_not have_tag('p', :count => 10)
|
159
160
|
expect(rendered).to_not have_tag('p', :count => 4..8)
|
160
161
|
expect(rendered).to_not have_tag('p', :min => 11)
|
@@ -163,151 +164,150 @@ describe 'have_tag' do
|
|
163
164
|
expect(rendered).to_not have_tag('p', :maximum => 2)
|
164
165
|
end
|
165
166
|
|
166
|
-
it
|
167
|
+
it 'should not find tags and display appropriate message(with :count)' do
|
167
168
|
expect {
|
168
169
|
expect(rendered).to have_tag('p', :count => 10)
|
169
170
|
}.to raise_spec_error(
|
170
|
-
%
|
171
|
+
%{expected following:\n#{rendered}\nto have 10 element(s) matching "p", found 3.}
|
171
172
|
)
|
172
173
|
|
173
174
|
expect {
|
174
175
|
expect(rendered).to have_tag('p', :count => 4..8)
|
175
176
|
}.to raise_spec_error(
|
176
|
-
%
|
177
|
+
%{expected following:\n#{rendered}\nto have at least 4 and at most 8 element(s) matching "p", found 3.}
|
177
178
|
)
|
178
179
|
end
|
179
180
|
|
180
|
-
it
|
181
|
+
it 'should find unexpected tags and display appropriate message(with :count)' do
|
181
182
|
expect {
|
182
183
|
expect(rendered).to_not have_tag('p', :count => 3)
|
183
184
|
}.to raise_spec_error(
|
184
|
-
%
|
185
|
+
%{expected following:\n#{rendered}\nto NOT have 3 element(s) matching "p", but found.}
|
185
186
|
)
|
186
187
|
|
187
188
|
expect {
|
188
189
|
expect(rendered).to_not have_tag('p', :count => 1..3)
|
189
190
|
}.to raise_spec_error(
|
190
|
-
%
|
191
|
+
%{expected following:\n#{rendered}\nto NOT have at least 1 and at most 3 element(s) matching "p", but found 3.}
|
191
192
|
)
|
192
193
|
end
|
193
194
|
|
194
|
-
it
|
195
|
+
it 'should not find tags and display appropriate message(with :minimum)' do
|
195
196
|
expect {
|
196
197
|
expect(rendered).to have_tag('p', :min => 100)
|
197
198
|
}.to raise_spec_error(
|
198
|
-
%
|
199
|
+
%{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
199
200
|
)
|
200
201
|
expect {
|
201
202
|
expect(rendered).to have_tag('p', :minimum => 100)
|
202
203
|
}.to raise_spec_error(
|
203
|
-
%
|
204
|
+
%{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
204
205
|
)
|
205
206
|
end
|
206
207
|
|
207
|
-
it
|
208
|
+
it 'should find unexpected tags and display appropriate message(with :minimum)' do
|
208
209
|
expect {
|
209
210
|
expect(rendered).to_not have_tag('p', :min => 2)
|
210
211
|
}.to raise_spec_error(
|
211
|
-
%
|
212
|
+
%{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
212
213
|
)
|
213
214
|
expect {
|
214
215
|
expect(rendered).to_not have_tag('p', :minimum => 2)
|
215
216
|
}.to raise_spec_error(
|
216
|
-
%
|
217
|
+
%{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
217
218
|
)
|
218
219
|
end
|
219
220
|
|
220
|
-
it
|
221
|
+
it 'should not find tags and display appropriate message(with :maximum)' do
|
221
222
|
expect {
|
222
223
|
expect(rendered).to have_tag('p', :max => 2)
|
223
224
|
}.to raise_spec_error(
|
224
|
-
%
|
225
|
+
%{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
225
226
|
)
|
226
227
|
expect { expect(rendered).to have_tag('p', :maximum => 2) }.to raise_spec_error(
|
227
|
-
%
|
228
|
+
%{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
228
229
|
)
|
229
230
|
end
|
230
231
|
|
231
|
-
it
|
232
|
+
it 'should find unexpected tags and display appropriate message(with :maximum)' do
|
232
233
|
expect {
|
233
234
|
expect(rendered).to_not have_tag('p', :max => 5)
|
234
235
|
}.to raise_spec_error(
|
235
|
-
%
|
236
|
+
%{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
236
237
|
)
|
237
238
|
expect {
|
238
239
|
expect(rendered).to_not have_tag('p', :maximum => 5)
|
239
240
|
}.to raise_spec_error(
|
240
|
-
%
|
241
|
+
%{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
241
242
|
)
|
242
243
|
end
|
243
244
|
|
244
|
-
it
|
245
|
+
it 'should raise error when wrong params specified' do
|
245
246
|
expect {
|
246
247
|
expect(rendered).to have_tag('div', :count => 'string')
|
247
248
|
}.to raise_error(/wrong :count/)
|
248
249
|
|
249
|
-
|
250
|
+
wrong_params_error_msg1 = ':count with :minimum or :maximum has no sence!'
|
250
251
|
|
251
252
|
expect {
|
252
253
|
expect(rendered).to have_tag('div', :count => 2, :minimum => 1)
|
253
|
-
}.to raise_error(
|
254
|
+
}.to raise_error(wrong_params_error_msg1)
|
254
255
|
|
255
256
|
expect {
|
256
257
|
expect(rendered).to have_tag('div', :count => 2, :min => 1)
|
257
|
-
}.to raise_error(
|
258
|
+
}.to raise_error(wrong_params_error_msg1)
|
258
259
|
|
259
260
|
expect {
|
260
261
|
expect(rendered).to have_tag('div', :count => 2, :maximum => 1)
|
261
|
-
}.to raise_error(
|
262
|
+
}.to raise_error(wrong_params_error_msg1)
|
262
263
|
|
263
264
|
expect {
|
264
265
|
expect(rendered).to have_tag('div', :count => 2, :max => 1)
|
265
|
-
}.to raise_error(
|
266
|
+
}.to raise_error(wrong_params_error_msg1)
|
266
267
|
|
267
|
-
|
268
|
+
wrong_params_error_msg2 = ':minimum should be less than :maximum!'
|
268
269
|
|
269
270
|
expect {
|
270
271
|
expect(rendered).to have_tag('div', :minimum => 2, :maximum => 1)
|
271
|
-
}.to raise_error(
|
272
|
+
}.to raise_error(wrong_params_error_msg2)
|
272
273
|
|
273
|
-
[
|
274
|
+
[4..1, -2..6, 'a'..'z', 3..-9].each do |range|
|
274
275
|
expect {
|
275
|
-
expect(rendered).to have_tag('div', :count => range
|
276
|
-
}.to raise_error("Your :count range(#{range
|
276
|
+
expect(rendered).to have_tag('div', :count => range)
|
277
|
+
}.to raise_error("Your :count range(#{range}) has no sence!")
|
277
278
|
end
|
278
279
|
end
|
279
280
|
end
|
280
281
|
|
281
|
-
context
|
282
|
+
context '[with :text/:seen specified]' do
|
282
283
|
asset 'quotes'
|
283
284
|
|
284
|
-
context 'using standard syntax' do
|
285
|
-
|
286
|
-
it "should find tags" do
|
285
|
+
context '[using standard syntax]' do
|
286
|
+
it 'should find tags' do
|
287
287
|
expect(rendered).to have_tag('div', :text => 'sample text')
|
288
288
|
expect(rendered).to have_tag('p', :text => 'one')
|
289
289
|
expect(rendered).to have_tag('div', :text => /SAMPLE/i)
|
290
290
|
expect(rendered).to have_tag('span', :text => "sample with 'single' quotes")
|
291
|
-
expect(rendered).to have_tag('span', :text => %
|
291
|
+
expect(rendered).to have_tag('span', :text => %(sample with 'single' and "double" quotes))
|
292
292
|
expect(rendered).to have_tag('span', :text => /sample with 'single' and "double" quotes/)
|
293
293
|
|
294
294
|
expect(rendered).to have_tag('p', :seen => 'content with ignored spaces around')
|
295
295
|
expect(rendered).to have_tag('p', :seen => 'content with ignored spaces in')
|
296
296
|
expect(rendered).to have_tag('p', :seen => 'content with nbsp and spaces around')
|
297
297
|
|
298
|
-
expect(rendered).to have_tag('p',
|
299
|
-
expect(rendered).to have_tag('pre',
|
298
|
+
expect(rendered).to have_tag('p', :text => 'content with nbsp') unless Nokogiri::VERSION == '1.5.11'
|
299
|
+
expect(rendered).to have_tag('pre', :text => " 1. bla \n 2. bla ")
|
300
300
|
end
|
301
301
|
|
302
|
-
it
|
302
|
+
it 'should find with unicode text specified' do
|
303
303
|
expect {
|
304
|
-
expect(rendered).to have_tag('a', :text =>
|
304
|
+
expect(rendered).to have_tag('a', :text => 'học')
|
305
305
|
}.not_to raise_error
|
306
306
|
|
307
|
-
expect(rendered).to have_tag('a', :text =>
|
307
|
+
expect(rendered).to have_tag('a', :text => 'học')
|
308
308
|
end
|
309
309
|
|
310
|
-
it
|
310
|
+
it 'should not find tags' do
|
311
311
|
expect(rendered).to_not have_tag('p', :text => 'text does not present')
|
312
312
|
expect(rendered).to_not have_tag('strong', :text => 'text does not present')
|
313
313
|
expect(rendered).to_not have_tag('p', :text => /text does not present/)
|
@@ -323,65 +323,63 @@ describe 'have_tag' do
|
|
323
323
|
expect(rendered).to_not have_tag('pre', :text => "1. bla\n2. bla")
|
324
324
|
end
|
325
325
|
|
326
|
-
it
|
326
|
+
it 'should invoke #to_s method for :text' do
|
327
327
|
expect {
|
328
|
-
expect(rendered).to_not have_tag('p', :text => 100500
|
329
|
-
expect(rendered).to have_tag('p', :text => 315
|
328
|
+
expect(rendered).to_not have_tag('p', :text => 100500)
|
329
|
+
expect(rendered).to have_tag('p', :text => 315)
|
330
330
|
}.to_not raise_exception
|
331
331
|
end
|
332
332
|
|
333
|
-
it
|
334
|
-
# TODO make diffable,maybe...
|
333
|
+
it 'should not find tags and display appropriate message' do
|
334
|
+
# TODO: make diffable,maybe...
|
335
335
|
expect {
|
336
336
|
expect(rendered).to have_tag('div', :text => 'SAMPLE text')
|
337
337
|
}.to raise_spec_error(
|
338
|
-
%
|
338
|
+
%("SAMPLE text" expected within "div" in following template:\n#{rendered})
|
339
339
|
)
|
340
340
|
expect {
|
341
341
|
expect(rendered).to have_tag('div', :text => /SAMPLE tekzt/i)
|
342
342
|
}.to raise_spec_error(
|
343
|
-
%
|
343
|
+
%(/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered})
|
344
344
|
)
|
345
345
|
end
|
346
346
|
|
347
|
-
it
|
347
|
+
it 'should find unexpected tags and display appropriate message' do
|
348
348
|
expect {
|
349
349
|
expect(rendered).to_not have_tag('div', :text => 'sample text')
|
350
350
|
}.to raise_spec_error(
|
351
|
-
%
|
351
|
+
%("sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.)
|
352
352
|
)
|
353
353
|
expect {
|
354
354
|
expect(rendered).to_not have_tag('div', :text => /SAMPLE text/i)
|
355
355
|
}.to raise_spec_error(
|
356
|
-
%
|
356
|
+
%(/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.)
|
357
357
|
)
|
358
358
|
end
|
359
|
-
|
360
359
|
end
|
361
360
|
|
362
|
-
context 'using alternative syntax(with_text/without_text)' do
|
363
|
-
|
364
|
-
it "should raise exception when used outside any other tag matcher" do
|
361
|
+
context '[using alternative syntax(with_text/without_text)]' do
|
362
|
+
it 'should raise exception when used outside any other tag matcher' do
|
365
363
|
expect {
|
366
364
|
with_text 'sample text'
|
367
|
-
}.to raise_error(StandardError
|
365
|
+
}.to raise_error(StandardError, /inside "have_tag"/)
|
368
366
|
expect {
|
369
367
|
without_text 'sample text'
|
370
|
-
}.to raise_error(StandardError
|
368
|
+
}.to raise_error(StandardError, /inside "have_tag"/)
|
371
369
|
end
|
372
370
|
|
373
|
-
it
|
371
|
+
it 'should raise exception when used with block' do
|
374
372
|
expect {
|
375
373
|
expect(rendered).to have_tag('div') do
|
376
374
|
with_text 'sample text' do
|
377
375
|
puts 'bla'
|
378
376
|
end
|
379
377
|
end
|
380
|
-
}.to raise_error(ArgumentError
|
378
|
+
}.to raise_error(ArgumentError, /does not accept block/)
|
381
379
|
|
382
380
|
expect {
|
383
381
|
expect(rendered).to have_tag('div') do
|
384
|
-
with_text
|
382
|
+
with_text('sample text', proc { puts 'bla' })
|
385
383
|
end
|
386
384
|
}.to raise_error(ArgumentError)
|
387
385
|
|
@@ -391,16 +389,16 @@ describe 'have_tag' do
|
|
391
389
|
puts 'bla'
|
392
390
|
end
|
393
391
|
end
|
394
|
-
}.to raise_error(ArgumentError
|
392
|
+
}.to raise_error(ArgumentError, /does not accept block/)
|
395
393
|
|
396
394
|
expect {
|
397
395
|
expect(rendered).to have_tag('div') do
|
398
|
-
without_text
|
396
|
+
without_text('sample text', proc { puts 'bla' })
|
399
397
|
end
|
400
398
|
}.to raise_error(ArgumentError)
|
401
399
|
end
|
402
400
|
|
403
|
-
it
|
401
|
+
it 'should find tags' do
|
404
402
|
expect(rendered).to have_tag('div') do
|
405
403
|
with_text 'sample text'
|
406
404
|
end
|
@@ -418,16 +416,17 @@ describe 'have_tag' do
|
|
418
416
|
end
|
419
417
|
|
420
418
|
expect(rendered).to have_tag('span') do
|
421
|
-
with_text %
|
419
|
+
with_text %(sample with 'single' and "double" quotes)
|
422
420
|
end
|
423
421
|
|
424
422
|
expect(rendered).to have_tag('span') do
|
425
423
|
with_text /sample with 'single' and "double" quotes/
|
426
424
|
end
|
427
425
|
|
428
|
-
|
429
|
-
|
430
|
-
|
426
|
+
unless Nokogiri::VERSION == '1.5.11'
|
427
|
+
expect(rendered).to have_tag('p') do
|
428
|
+
with_text 'content with nbsp'
|
429
|
+
end
|
431
430
|
end
|
432
431
|
|
433
432
|
expect(rendered).to have_tag('pre') do
|
@@ -435,7 +434,7 @@ describe 'have_tag' do
|
|
435
434
|
end
|
436
435
|
end
|
437
436
|
|
438
|
-
it
|
437
|
+
it 'should not find tags' do
|
439
438
|
expect(rendered).to have_tag('p') do
|
440
439
|
but_without_text 'text does not present'
|
441
440
|
without_text 'text does not present'
|
@@ -457,13 +456,13 @@ describe 'have_tag' do
|
|
457
456
|
end
|
458
457
|
end
|
459
458
|
|
460
|
-
it
|
459
|
+
it 'should not find tags and display appropriate message' do
|
461
460
|
expect {
|
462
461
|
expect(rendered).to have_tag('div') do
|
463
462
|
with_text 'SAMPLE text'
|
464
463
|
end
|
465
464
|
}.to raise_spec_error(
|
466
|
-
|
465
|
+
/"SAMPLE text" expected within "div" in following template:/
|
467
466
|
)
|
468
467
|
|
469
468
|
expect {
|
@@ -471,17 +470,17 @@ describe 'have_tag' do
|
|
471
470
|
with_text /SAMPLE tekzt/i
|
472
471
|
end
|
473
472
|
}.to raise_spec_error(
|
474
|
-
%
|
473
|
+
%r{/SAMPLE tekzt/i regexp expected within "div" in following template:}
|
475
474
|
)
|
476
475
|
end
|
477
476
|
|
478
|
-
it
|
477
|
+
it 'should find unexpected tags and display appropriate message' do
|
479
478
|
expect {
|
480
479
|
expect(rendered).to have_tag('div') do
|
481
480
|
without_text 'sample text'
|
482
481
|
end
|
483
482
|
}.to raise_spec_error(
|
484
|
-
|
483
|
+
/"sample text" unexpected within "div" in following template:/
|
485
484
|
)
|
486
485
|
|
487
486
|
expect {
|
@@ -489,59 +488,57 @@ describe 'have_tag' do
|
|
489
488
|
without_text /SAMPLE text/i
|
490
489
|
end
|
491
490
|
}.to raise_spec_error(
|
492
|
-
%
|
491
|
+
%r{/SAMPLE text/i regexp unexpected within "div" in following template:}
|
493
492
|
)
|
494
493
|
end
|
495
|
-
|
496
494
|
end
|
497
|
-
|
498
495
|
end
|
499
496
|
|
500
|
-
context
|
497
|
+
context '[mixed matching]' do
|
501
498
|
asset 'special'
|
502
499
|
|
503
|
-
it
|
504
|
-
expect(rendered).to have_tag(
|
500
|
+
it 'should find tags by count and exact content' do
|
501
|
+
expect(rendered).to have_tag('td', :text => 'a', :count => 3)
|
505
502
|
end
|
506
503
|
|
507
|
-
it
|
508
|
-
expect(rendered).to have_tag(
|
504
|
+
it 'should find tags by count and rough content(regexp)' do
|
505
|
+
expect(rendered).to have_tag('td', :text => /user/, :count => 3)
|
509
506
|
end
|
510
507
|
|
511
|
-
it
|
512
|
-
expect(rendered).to have_tag(
|
513
|
-
expect(rendered).to_not have_tag(
|
508
|
+
it 'should find tags with exact content and additional attributes' do
|
509
|
+
expect(rendered).to have_tag('td', :text => 'a', :with => { :id => 'special' })
|
510
|
+
expect(rendered).to_not have_tag('td', :text => 'a', :with => { :id => 'other-special' })
|
514
511
|
end
|
515
512
|
|
516
|
-
it
|
517
|
-
expect(rendered).to have_tag(
|
518
|
-
expect(rendered).to_not have_tag(
|
513
|
+
it 'should find tags with rough content and additional attributes' do
|
514
|
+
expect(rendered).to have_tag('td', :text => /user/, :with => { :id => 'other-special' })
|
515
|
+
expect(rendered).to_not have_tag('td', :text => /user/, :with => { :id => 'special' })
|
519
516
|
end
|
520
517
|
|
521
|
-
it
|
522
|
-
expect(rendered).to have_tag(
|
523
|
-
expect(rendered).to have_tag(
|
518
|
+
it 'should find tags with count and additional attributes' do
|
519
|
+
expect(rendered).to have_tag('div', :with => { :class => 'one' }, :count => 6)
|
520
|
+
expect(rendered).to have_tag('div', :with => { :class => 'two' }, :count => 3)
|
524
521
|
end
|
525
522
|
|
526
|
-
it
|
527
|
-
expect(rendered).to have_tag(
|
528
|
-
expect(rendered).to_not have_tag(
|
529
|
-
expect(rendered).to_not have_tag(
|
530
|
-
expect(rendered).to_not have_tag(
|
523
|
+
it 'should find tags with count, exact text and additional attributes' do
|
524
|
+
expect(rendered).to have_tag('div', :with => { :class => 'one' }, :count => 3, :text => 'text')
|
525
|
+
expect(rendered).to_not have_tag('div', :with => { :class => 'one' }, :count => 5, :text => 'text')
|
526
|
+
expect(rendered).to_not have_tag('div', :with => { :class => 'one' }, :count => 3, :text => 'other text')
|
527
|
+
expect(rendered).to_not have_tag('div', :with => { :class => 'two' }, :count => 3, :text => 'text')
|
531
528
|
end
|
532
529
|
|
533
|
-
it
|
534
|
-
expect(rendered).to have_tag(
|
535
|
-
expect(rendered).to have_tag(
|
536
|
-
expect(rendered).to_not have_tag(
|
537
|
-
expect(rendered).to_not have_tag(
|
530
|
+
it 'should find tags with count, regexp text and additional attributes' do
|
531
|
+
expect(rendered).to have_tag('div', :with => { :class => 'one' }, :count => 2, :text => /bla/)
|
532
|
+
expect(rendered).to have_tag('div', :with => { :class => 'two' }, :count => 1, :text => /bla/)
|
533
|
+
expect(rendered).to_not have_tag('div', :with => { :class => 'one' }, :count => 5, :text => /bla/)
|
534
|
+
expect(rendered).to_not have_tag('div', :with => { :class => 'one' }, :count => 6, :text => /other bla/)
|
538
535
|
end
|
539
536
|
end
|
540
537
|
|
541
|
-
context
|
538
|
+
context '[nested matching]' do
|
542
539
|
asset 'ordered_list'
|
543
540
|
|
544
|
-
it
|
541
|
+
it 'should find tags' do
|
545
542
|
expect(rendered).to have_tag('ol') {
|
546
543
|
with_tag('li', :text => 'list item 1')
|
547
544
|
with_tag('li', :text => 'list item 2')
|
@@ -553,7 +550,7 @@ describe 'have_tag' do
|
|
553
550
|
}
|
554
551
|
end
|
555
552
|
|
556
|
-
it
|
553
|
+
it 'should not find tags' do
|
557
554
|
expect(rendered).to have_tag('ol') {
|
558
555
|
without_tag('div')
|
559
556
|
without_tag('li', :count => 2)
|
@@ -565,7 +562,7 @@ describe 'have_tag' do
|
|
565
562
|
}
|
566
563
|
end
|
567
564
|
|
568
|
-
it
|
565
|
+
it 'should handle do; end' do
|
569
566
|
expect {
|
570
567
|
expect(rendered).to have_tag('ol') do
|
571
568
|
with_tag('div')
|
@@ -573,44 +570,151 @@ describe 'have_tag' do
|
|
573
570
|
}.to raise_spec_error(/have at least 1 element matching "div", found 0/)
|
574
571
|
end
|
575
572
|
|
576
|
-
it
|
577
|
-
ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
|
578
|
-
|
573
|
+
it 'should not find tags and display appropriate message' do
|
579
574
|
expect {
|
580
575
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('div') }
|
581
|
-
}.to raise_spec_error(/
|
576
|
+
}.to raise_spec_error(/to have at least 1 element matching "div", found 0/)
|
582
577
|
|
583
578
|
expect {
|
584
579
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
|
585
|
-
}.to raise_spec_error(/
|
580
|
+
}.to raise_spec_error(/to have 10 element\(s\) matching "li", found 3/)
|
586
581
|
|
587
582
|
expect {
|
588
583
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
|
589
|
-
}.to raise_spec_error(
|
584
|
+
}.to raise_spec_error(%r{/SAMPLE text/i regexp expected within "li"})
|
590
585
|
end
|
591
586
|
end
|
592
587
|
|
593
|
-
context
|
594
|
-
asset '
|
588
|
+
context '[deep nesting]' do
|
589
|
+
asset 'multiple_lists'
|
595
590
|
|
596
|
-
|
591
|
+
it 'should allow deep nesting' do
|
592
|
+
expect(rendered).to have_tag('div') do
|
593
|
+
with_tag 'ul.numeric' do
|
594
|
+
with_tag 'li#one'
|
595
|
+
end
|
596
|
+
end
|
597
|
+
end
|
597
598
|
|
598
|
-
|
599
|
-
|
599
|
+
it 'should clear context between nested tags' do
|
600
|
+
expect(rendered).to have_tag('div') do |div|
|
601
|
+
expect(div).to have_tag 'ul.numeric'
|
602
|
+
expect(div).to have_tag 'ul.alpha'
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
it 'should narrow context when deep nesting' do
|
607
|
+
expect do
|
608
|
+
expect(rendered).to have_tag('div') do |div|
|
609
|
+
expect(div).to have_tag 'ul.numeric' do |ul_numeric|
|
610
|
+
expect(ul_numeric).to have_tag 'li#aye'
|
611
|
+
end
|
612
|
+
end
|
613
|
+
end .to raise_spec_error(/at least 1 element matching "li#aye", found 0/)
|
614
|
+
end
|
615
|
+
|
616
|
+
it 'should narrow context for with_text' do
|
617
|
+
expect do
|
618
|
+
expect(rendered).to have_tag('div') do |div|
|
619
|
+
expect(div).to have_tag 'ul.numeric' do
|
620
|
+
with_text 'A'
|
621
|
+
end
|
622
|
+
end
|
623
|
+
end .to raise_spec_error(/"A" expected within "ul.numeric"/)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
context '[find nested tags]' do
|
628
|
+
asset 'nested_matchers'
|
629
|
+
|
630
|
+
it 'with block parameters' do
|
631
|
+
expect(rendered).to have_tag('div#one') do |a|
|
632
|
+
expect(a).to have_tag 'p.find_me', :count => 2
|
633
|
+
|
634
|
+
expect(a).to have_tag 'b.nested', :count => 3
|
635
|
+
expect(a).to have_tag('p.deep-nesting', :count => 1) do |b|
|
636
|
+
expect(b).to have_tag 'b.nested', :count => 2
|
637
|
+
end
|
600
638
|
end
|
639
|
+
end
|
601
640
|
|
641
|
+
it 'with short_hand methods' do
|
642
|
+
expect(rendered).to have_tag('div#one') do
|
643
|
+
with_tag 'p.find_me', :count => 2
|
644
|
+
|
645
|
+
with_tag 'b.nested', :count => 3
|
646
|
+
with_tag('p.deep-nesting', :count => 1) do
|
647
|
+
with_tag 'b.nested', :count => 2
|
648
|
+
end
|
649
|
+
end
|
602
650
|
end
|
651
|
+
end
|
603
652
|
|
604
|
-
|
653
|
+
context '[backwards compatibility for unnamed arguments]' do
|
654
|
+
asset 'quotes'
|
605
655
|
|
606
|
-
|
656
|
+
context '[string as second argument]' do
|
657
|
+
it 'should map a string argument to :text => string' do
|
658
|
+
expect(rendered).to have_tag('div', 'sample text')
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
context '[Regexp as second argument]' do
|
663
|
+
it 'should match against a valid Regexp' do
|
607
664
|
expect(rendered).to have_tag('div', /sample\s/)
|
608
665
|
end
|
609
666
|
|
610
|
-
it
|
611
|
-
expect(rendered).to_not have_tag('div',
|
667
|
+
it 'should not match against an invalid Regexp' do
|
668
|
+
expect(rendered).to_not have_tag('div', /not matching/)
|
612
669
|
end
|
613
670
|
end
|
614
671
|
end
|
615
672
|
|
673
|
+
context '[html and body elements]' do
|
674
|
+
asset 'document'
|
675
|
+
|
676
|
+
context '[matching attributes]' do
|
677
|
+
it 'should find the html element with specified attributes' do
|
678
|
+
expect(rendered).to have_tag('html', :class => 'nojs')
|
679
|
+
end
|
680
|
+
|
681
|
+
it 'should find the body element with specified attributes' do
|
682
|
+
expect(rendered).to have_tag('body', :class => 'container')
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'should not find the html element with specified attributes' do
|
686
|
+
expect(rendered).to have_tag('html', :class => 'nonexistent')
|
687
|
+
end
|
688
|
+
|
689
|
+
it 'should not find the body element with specified attributes' do
|
690
|
+
expect(rendered).to have_tag('body', :class => 'nonexistent')
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
context '[quirk: when no attributes specified, match is not intended to work]' do
|
695
|
+
it '<html> positive match should raise error' do
|
696
|
+
expect {
|
697
|
+
expect(rendered).to have_tag('html')
|
698
|
+
}.to raise_error(ArgumentError)
|
699
|
+
end
|
700
|
+
|
701
|
+
it '<html> negative match should raise error' do
|
702
|
+
expect {
|
703
|
+
expect(rendered).to_not have_tag('html')
|
704
|
+
}.to raise_error(ArgumentError)
|
705
|
+
end
|
706
|
+
|
707
|
+
it '<body> positive match should raise error' do
|
708
|
+
expect {
|
709
|
+
expect(rendered).to have_tag('body')
|
710
|
+
}.to raise_error(ArgumentError)
|
711
|
+
end
|
712
|
+
|
713
|
+
it '<body> negative match should raise error' do
|
714
|
+
expect {
|
715
|
+
expect(rendered).to_not have_tag('body')
|
716
|
+
}.to raise_error(ArgumentError)
|
717
|
+
end
|
718
|
+
end
|
719
|
+
end
|
616
720
|
end
|