rspec-html-matchers 0.4.4 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +38 -27
- data/features/support/env.rb +0 -5
- data/lib/rspec-html-matchers.rb +36 -30
- data/spec/fixtures/form.html +1 -0
- data/spec/{matchers/form_matchers_spec.rb → form_matchers_spec.rb} +52 -62
- data/spec/{matchers/have_tag_spec.rb → have_tag_spec.rb} +221 -139
- data/spec/spec_helper.rb +53 -4
- metadata +66 -41
- data/.gitignore +0 -18
- data/.rspec +0 -1
- data/.travis.yml +0 -13
- data/.yardopts +0 -4
- data/Gemfile +0 -2
- data/Rakefile +0 -32
- data/cucumber.yml +0 -1
- data/rspec-html-matchers.gemspec +0 -34
@@ -6,92 +6,108 @@ describe 'have_tag' do
|
|
6
6
|
asset 'search_and_submit'
|
7
7
|
|
8
8
|
it "should have right description" do
|
9
|
-
have_tag('div').description.
|
10
|
-
have_tag('div.class').description.
|
11
|
-
have_tag('div#id').description.
|
9
|
+
expect(have_tag('div').description).to eq 'have at least 1 element matching "div"'
|
10
|
+
expect(have_tag('div.class').description).to eq 'have at least 1 element matching "div.class"'
|
11
|
+
expect(have_tag('div#id').description).to eq 'have at least 1 element matching "div#id"'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should find tags" do
|
15
|
-
rendered.
|
16
|
-
rendered.
|
17
|
-
rendered.
|
18
|
-
rendered.
|
19
|
-
rendered.
|
15
|
+
expect(rendered).to have_tag('div')
|
16
|
+
expect(rendered).to have_tag(:div)
|
17
|
+
expect(rendered).to have_tag('div#div')
|
18
|
+
expect(rendered).to have_tag('p.paragraph')
|
19
|
+
expect(rendered).to have_tag('div p strong')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not find tags" do
|
23
|
-
rendered.
|
24
|
-
rendered.
|
25
|
-
rendered.
|
26
|
-
rendered.
|
27
|
-
rendered.
|
23
|
+
expect(rendered).to_not have_tag('span')
|
24
|
+
expect(rendered).to_not have_tag(:span)
|
25
|
+
expect(rendered).to_not have_tag('span#id')
|
26
|
+
expect(rendered).to_not have_tag('span#class')
|
27
|
+
expect(rendered).to_not have_tag('div div span')
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not find tags and display appropriate message" do
|
31
|
-
expect {
|
31
|
+
expect {
|
32
|
+
expect(rendered).to have_tag('span')
|
33
|
+
}.to raise_spec_error(
|
32
34
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span", found 0.}
|
33
35
|
)
|
34
|
-
expect {
|
36
|
+
expect {
|
37
|
+
expect(rendered).to have_tag('span#some_id')
|
38
|
+
}.to raise_spec_error(
|
35
39
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span#some_id", found 0.}
|
36
40
|
)
|
37
|
-
expect {
|
41
|
+
expect {
|
42
|
+
expect(rendered).to have_tag('span.some_class')
|
43
|
+
}.to raise_spec_error(
|
38
44
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span.some_class", found 0.}
|
39
45
|
)
|
40
46
|
end
|
41
47
|
|
42
48
|
it "should find unexpected tags and display appropriate message" do
|
43
|
-
expect {
|
49
|
+
expect {
|
50
|
+
expect(rendered).to_not have_tag('div')
|
51
|
+
}.to raise_spec_error(
|
44
52
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "div", found 2.}
|
45
53
|
)
|
46
|
-
expect {
|
54
|
+
expect {
|
55
|
+
expect(rendered).to_not have_tag('div#div')
|
56
|
+
}.to raise_spec_error(
|
47
57
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "div#div", found 1.}
|
48
58
|
)
|
49
|
-
expect {
|
59
|
+
expect {
|
60
|
+
expect(rendered).to_not have_tag('p.paragraph')
|
61
|
+
}.to raise_spec_error(
|
50
62
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.}
|
51
63
|
)
|
52
64
|
end
|
53
65
|
|
54
66
|
context "with additional HTML attributes(:with option)" do
|
55
67
|
it "should find tags" do
|
56
|
-
rendered.
|
57
|
-
rendered.
|
68
|
+
expect(rendered).to have_tag('input#search',:with => {:type => "text"})
|
69
|
+
expect(rendered).to have_tag(:input ,:with => {:type => "submit", :value => "Save"})
|
58
70
|
end
|
59
71
|
|
60
72
|
it "should find tags that have classes specified via array(or string)" do
|
61
|
-
rendered.
|
62
|
-
rendered.
|
73
|
+
expect(rendered).to have_tag('div',:with => {:class => %w(class-one class-two)})
|
74
|
+
expect(rendered).to have_tag('div',:with => {:class => 'class-two class-one'})
|
63
75
|
end
|
64
76
|
|
65
77
|
it "should not find tags that have classes specified via array" do
|
66
|
-
rendered.
|
78
|
+
expect(rendered).to_not have_tag('div',:with => {:class => %w(class-other class-two)})
|
67
79
|
end
|
68
80
|
|
69
81
|
it "should not find tags that have classes specified via array and display appropriate message" do
|
70
82
|
expect {
|
71
|
-
rendered.
|
83
|
+
expect(rendered).to have_tag('div',:with => {:class => %w(class-other class-two)})
|
72
84
|
}.to raise_spec_error(
|
73
85
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
74
86
|
)
|
75
87
|
expect {
|
76
|
-
rendered.
|
88
|
+
expect(rendered).to have_tag('div',:with => {:class => 'class-other class-two'})
|
77
89
|
}.to raise_spec_error(
|
78
90
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
79
91
|
)
|
80
92
|
end
|
81
93
|
|
82
94
|
it "should not find tags" do
|
83
|
-
rendered.
|
84
|
-
rendered.
|
95
|
+
expect(rendered).to_not have_tag('input#search',:with => {:type => "some_other_type"})
|
96
|
+
expect(rendered).to_not have_tag(:input, :with => {:type => "some_other_type"})
|
85
97
|
end
|
86
98
|
|
87
99
|
it "should not find tags and display appropriate message" do
|
88
|
-
expect {
|
100
|
+
expect {
|
101
|
+
expect(rendered).to have_tag('input#search',:with => {:type => "some_other_type"})
|
102
|
+
}.to raise_spec_error(
|
89
103
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "input#search[type='some_other_type']", found 0.}
|
90
104
|
)
|
91
105
|
end
|
92
106
|
|
93
107
|
it "should find unexpected tags and display appropriate message" do
|
94
|
-
expect {
|
108
|
+
expect {
|
109
|
+
expect(rendered).to_not have_tag('input#search',:with => {:type => "text"})
|
110
|
+
}.to raise_spec_error(
|
95
111
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "input#search[type='text']", found 1.}
|
96
112
|
)
|
97
113
|
end
|
@@ -102,16 +118,16 @@ describe 'have_tag' do
|
|
102
118
|
asset 'single_element'
|
103
119
|
|
104
120
|
it "should find tags that have classes specified via array (or string)" do
|
105
|
-
rendered.
|
106
|
-
rendered.
|
107
|
-
rendered.
|
108
|
-
rendered.
|
121
|
+
expect(rendered).to_not have_tag('div', :without => { :class => %w(foo bar) })
|
122
|
+
expect(rendered).to_not have_tag('div', :without => { :class => 'foo bar' })
|
123
|
+
expect(rendered).to_not have_tag('div', :without => { :class => 'foo' })
|
124
|
+
expect(rendered).to_not have_tag('div', :without => { :class => 'bar' })
|
109
125
|
end
|
110
126
|
|
111
127
|
it "should not find tags that have classes specified via array (or string)" do
|
112
|
-
rendered.
|
113
|
-
rendered.
|
114
|
-
rendered.
|
128
|
+
expect(rendered).to have_tag('div', :without => { :class => %w(foo baz) })
|
129
|
+
expect(rendered).to have_tag('div', :without => { :class => 'foo baz' })
|
130
|
+
expect(rendered).to have_tag('div', :without => { :class => 'baz' })
|
115
131
|
end
|
116
132
|
end
|
117
133
|
end
|
@@ -120,100 +136,144 @@ describe 'have_tag' do
|
|
120
136
|
asset 'paragraphs'
|
121
137
|
|
122
138
|
it "should have right description" do
|
123
|
-
have_tag('div', :count => 100500).description.
|
139
|
+
expect(have_tag('div', :count => 100500).description).to eq 'have 100500 element(s) matching "div"'
|
124
140
|
end
|
125
141
|
|
126
142
|
it "should find tags" do
|
127
|
-
rendered.
|
128
|
-
rendered.
|
143
|
+
expect(rendered).to have_tag('p', :count => 3)
|
144
|
+
expect(rendered).to have_tag('p', :count => 2..3)
|
129
145
|
end
|
130
146
|
|
131
147
|
it "should find tags when :minimum specified" do
|
132
|
-
rendered.
|
133
|
-
rendered.
|
148
|
+
expect(rendered).to have_tag('p', :min => 3)
|
149
|
+
expect(rendered).to have_tag('p', :minimum => 2)
|
134
150
|
end
|
135
151
|
|
136
152
|
it "should find tags when :maximum specified" do
|
137
|
-
rendered.
|
138
|
-
rendered.
|
153
|
+
expect(rendered).to have_tag('p', :max => 4)
|
154
|
+
expect(rendered).to have_tag('p', :maximum => 3)
|
139
155
|
end
|
140
156
|
|
141
157
|
it "should not find tags(with :count, :minimum or :maximum specified)" do
|
142
|
-
rendered.
|
143
|
-
rendered.
|
144
|
-
rendered.
|
145
|
-
rendered.
|
146
|
-
rendered.
|
147
|
-
rendered.
|
158
|
+
expect(rendered).to_not have_tag('p', :count => 10)
|
159
|
+
expect(rendered).to_not have_tag('p', :count => 4..8)
|
160
|
+
expect(rendered).to_not have_tag('p', :min => 11)
|
161
|
+
expect(rendered).to_not have_tag('p', :minimum => 10)
|
162
|
+
expect(rendered).to_not have_tag('p', :max => 2)
|
163
|
+
expect(rendered).to_not have_tag('p', :maximum => 2)
|
148
164
|
end
|
149
165
|
|
150
166
|
it "should not find tags and display appropriate message(with :count)" do
|
151
|
-
expect {
|
167
|
+
expect {
|
168
|
+
expect(rendered).to have_tag('p', :count => 10)
|
169
|
+
}.to raise_spec_error(
|
152
170
|
%Q{expected following:\n#{rendered}\nto have 10 element(s) matching "p", found 3.}
|
153
171
|
)
|
154
172
|
|
155
|
-
expect {
|
173
|
+
expect {
|
174
|
+
expect(rendered).to have_tag('p', :count => 4..8)
|
175
|
+
}.to raise_spec_error(
|
156
176
|
%Q{expected following:\n#{rendered}\nto have at least 4 and at most 8 element(s) matching "p", found 3.}
|
157
177
|
)
|
158
178
|
end
|
159
179
|
|
160
180
|
it "should find unexpected tags and display appropriate message(with :count)" do
|
161
|
-
expect {
|
181
|
+
expect {
|
182
|
+
expect(rendered).to_not have_tag('p', :count => 3)
|
183
|
+
}.to raise_spec_error(
|
162
184
|
%Q{expected following:\n#{rendered}\nto NOT have 3 element(s) matching "p", but found.}
|
163
185
|
)
|
164
186
|
|
165
|
-
expect {
|
187
|
+
expect {
|
188
|
+
expect(rendered).to_not have_tag('p', :count => 1..3)
|
189
|
+
}.to raise_spec_error(
|
166
190
|
%Q{expected following:\n#{rendered}\nto NOT have at least 1 and at most 3 element(s) matching "p", but found 3.}
|
167
191
|
)
|
168
192
|
end
|
169
193
|
|
170
194
|
it "should not find tags and display appropriate message(with :minimum)" do
|
171
|
-
expect {
|
195
|
+
expect {
|
196
|
+
expect(rendered).to have_tag('p', :min => 100)
|
197
|
+
}.to raise_spec_error(
|
172
198
|
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
173
199
|
)
|
174
|
-
expect {
|
200
|
+
expect {
|
201
|
+
expect(rendered).to have_tag('p', :minimum => 100)
|
202
|
+
}.to raise_spec_error(
|
175
203
|
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
176
204
|
)
|
177
205
|
end
|
178
206
|
|
179
207
|
it "should find unexpected tags and display appropriate message(with :minimum)" do
|
180
|
-
expect {
|
208
|
+
expect {
|
209
|
+
expect(rendered).to_not have_tag('p', :min => 2)
|
210
|
+
}.to raise_spec_error(
|
181
211
|
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
182
212
|
)
|
183
|
-
expect {
|
213
|
+
expect {
|
214
|
+
expect(rendered).to_not have_tag('p', :minimum => 2)
|
215
|
+
}.to raise_spec_error(
|
184
216
|
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
185
217
|
)
|
186
218
|
end
|
187
219
|
|
188
220
|
it "should not find tags and display appropriate message(with :maximum)" do
|
189
|
-
expect {
|
221
|
+
expect {
|
222
|
+
expect(rendered).to have_tag('p', :max => 2)
|
223
|
+
}.to raise_spec_error(
|
190
224
|
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
191
225
|
)
|
192
|
-
expect { rendered.
|
226
|
+
expect { expect(rendered).to have_tag('p', :maximum => 2) }.to raise_spec_error(
|
193
227
|
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
194
228
|
)
|
195
229
|
end
|
196
230
|
|
197
231
|
it "should find unexpected tags and display appropriate message(with :maximum)" do
|
198
|
-
expect {
|
232
|
+
expect {
|
233
|
+
expect(rendered).to_not have_tag('p', :max => 5)
|
234
|
+
}.to raise_spec_error(
|
199
235
|
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
200
236
|
)
|
201
|
-
expect {
|
237
|
+
expect {
|
238
|
+
expect(rendered).to_not have_tag('p', :maximum => 5)
|
239
|
+
}.to raise_spec_error(
|
202
240
|
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
203
241
|
)
|
204
242
|
end
|
205
243
|
|
206
244
|
it "should raise error when wrong params specified" do
|
207
|
-
expect {
|
245
|
+
expect {
|
246
|
+
expect(rendered).to have_tag('div', :count => 'string')
|
247
|
+
}.to raise_error(/wrong :count/)
|
248
|
+
|
208
249
|
wrong_params_error_msg_1 = ':count with :minimum or :maximum has no sence!'
|
209
|
-
|
210
|
-
expect {
|
211
|
-
|
212
|
-
|
250
|
+
|
251
|
+
expect {
|
252
|
+
expect(rendered).to have_tag('div', :count => 2, :minimum => 1)
|
253
|
+
}.to raise_error(wrong_params_error_msg_1)
|
254
|
+
|
255
|
+
expect {
|
256
|
+
expect(rendered).to have_tag('div', :count => 2, :min => 1)
|
257
|
+
}.to raise_error(wrong_params_error_msg_1)
|
258
|
+
|
259
|
+
expect {
|
260
|
+
expect(rendered).to have_tag('div', :count => 2, :maximum => 1)
|
261
|
+
}.to raise_error(wrong_params_error_msg_1)
|
262
|
+
|
263
|
+
expect {
|
264
|
+
expect(rendered).to have_tag('div', :count => 2, :max => 1)
|
265
|
+
}.to raise_error(wrong_params_error_msg_1)
|
266
|
+
|
213
267
|
wrong_params_error_msg_2 = ':minimum shold be less than :maximum!'
|
214
|
-
|
268
|
+
|
269
|
+
expect {
|
270
|
+
expect(rendered).to have_tag('div', :minimum => 2, :maximum => 1)
|
271
|
+
}.to raise_error(wrong_params_error_msg_2)
|
272
|
+
|
215
273
|
[ 4..1, -2..6, 'a'..'z', 3..-9 ].each do |range|
|
216
|
-
expect {
|
274
|
+
expect {
|
275
|
+
expect(rendered).to have_tag('div', :count => range )
|
276
|
+
}.to raise_error("Your :count range(#{range.to_s}) has no sence!")
|
217
277
|
end
|
218
278
|
end
|
219
279
|
end
|
@@ -224,54 +284,65 @@ describe 'have_tag' do
|
|
224
284
|
context 'using standard syntax' do
|
225
285
|
|
226
286
|
it "should find tags" do
|
227
|
-
rendered.
|
228
|
-
rendered.
|
229
|
-
rendered.
|
230
|
-
rendered.
|
231
|
-
rendered.
|
232
|
-
rendered.
|
233
|
-
|
234
|
-
rendered.
|
235
|
-
rendered.
|
287
|
+
expect(rendered).to have_tag('div', :text => 'sample text')
|
288
|
+
expect(rendered).to have_tag('p', :text => 'one')
|
289
|
+
expect(rendered).to have_tag('div', :text => /SAMPLE/i)
|
290
|
+
expect(rendered).to have_tag('span', :text => "sample with 'single' quotes")
|
291
|
+
expect(rendered).to have_tag('span', :text => %Q{sample with 'single' and "double" quotes})
|
292
|
+
expect(rendered).to have_tag('span', :text => /sample with 'single' and "double" quotes/)
|
293
|
+
|
294
|
+
expect(rendered).to have_tag('p', :text => 'content with nbsp')
|
295
|
+
expect(rendered).to have_tag('pre', :text => " 1. bla \n 2. bla ")
|
236
296
|
end
|
237
297
|
|
238
298
|
it "should find with unicode text specified" do
|
239
|
-
expect {
|
240
|
-
rendered.
|
299
|
+
expect {
|
300
|
+
expect(rendered).to have_tag('a', :text => "học")
|
301
|
+
}.not_to raise_error
|
302
|
+
|
303
|
+
expect(rendered).to have_tag('a', :text => "học")
|
241
304
|
end
|
242
305
|
|
243
306
|
it "should not find tags" do
|
244
|
-
rendered.
|
245
|
-
rendered.
|
246
|
-
rendered.
|
247
|
-
rendered.
|
307
|
+
expect(rendered).to_not have_tag('p', :text => 'text does not present')
|
308
|
+
expect(rendered).to_not have_tag('strong', :text => 'text does not present')
|
309
|
+
expect(rendered).to_not have_tag('p', :text => /text does not present/)
|
310
|
+
expect(rendered).to_not have_tag('strong', :text => /text does not present/)
|
248
311
|
|
249
|
-
rendered.
|
250
|
-
rendered.
|
312
|
+
expect(rendered).to_not have_tag('p', :text => 'contentwith nbsp')
|
313
|
+
expect(rendered).to_not have_tag('pre', :text => "1. bla\n2. bla")
|
251
314
|
end
|
252
315
|
|
253
316
|
it "should invoke #to_s method for :text" do
|
254
317
|
expect {
|
255
|
-
rendered.
|
256
|
-
rendered.
|
318
|
+
expect(rendered).to_not have_tag('p', :text => 100500 )
|
319
|
+
expect(rendered).to have_tag('p', :text => 315 )
|
257
320
|
}.to_not raise_exception
|
258
321
|
end
|
259
322
|
|
260
323
|
it "should not find tags and display appropriate message" do
|
261
324
|
# TODO make diffable,maybe...
|
262
|
-
expect {
|
325
|
+
expect {
|
326
|
+
expect(rendered).to have_tag('div', :text => 'SAMPLE text')
|
327
|
+
}.to raise_spec_error(
|
263
328
|
%Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
|
264
329
|
)
|
265
|
-
expect {
|
330
|
+
expect {
|
331
|
+
expect(rendered).to have_tag('div', :text => /SAMPLE tekzt/i)
|
332
|
+
}.to raise_spec_error(
|
266
333
|
%Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered}}
|
267
334
|
)
|
268
335
|
end
|
269
336
|
|
270
337
|
it "should find unexpected tags and display appropriate message" do
|
271
|
-
expect {
|
338
|
+
expect {
|
339
|
+
expect(rendered).to_not have_tag('div', :text => 'sample text')
|
340
|
+
}.to raise_spec_error(
|
272
341
|
%Q{"sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
273
342
|
)
|
274
|
-
expect {
|
343
|
+
expect {
|
344
|
+
expect(rendered).to_not have_tag('div', :text => /SAMPLE text/i)
|
345
|
+
}.to raise_spec_error(
|
275
346
|
%Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
276
347
|
)
|
277
348
|
end
|
@@ -281,90 +352,96 @@ describe 'have_tag' do
|
|
281
352
|
context 'using alternative syntax(with_text/without_text)' do
|
282
353
|
|
283
354
|
it "should raise exception when used outside any other tag matcher" do
|
284
|
-
expect {
|
285
|
-
|
355
|
+
expect {
|
356
|
+
with_text 'sample text'
|
357
|
+
}.to raise_error(StandardError,/inside "have_tag"/)
|
358
|
+
expect {
|
359
|
+
without_text 'sample text'
|
360
|
+
}.to raise_error(StandardError,/inside "have_tag"/)
|
286
361
|
end
|
287
362
|
|
288
363
|
it "should raise exception when used with block" do
|
289
364
|
expect {
|
290
|
-
rendered.
|
365
|
+
expect(rendered).to have_tag('div') do
|
291
366
|
with_text 'sample text' do
|
292
367
|
puts 'bla'
|
293
368
|
end
|
294
369
|
end
|
295
370
|
}.to raise_error(ArgumentError,/does not accept block/)
|
371
|
+
|
296
372
|
expect {
|
297
|
-
rendered.
|
373
|
+
expect(rendered).to have_tag('div') do
|
298
374
|
with_text 'sample text', proc { puts 'bla' }
|
299
375
|
end
|
300
376
|
}.to raise_error(ArgumentError)
|
301
377
|
|
302
378
|
expect {
|
303
|
-
rendered.
|
379
|
+
expect(rendered).to have_tag('div') do
|
304
380
|
without_text 'sample text' do
|
305
381
|
puts 'bla'
|
306
382
|
end
|
307
383
|
end
|
308
384
|
}.to raise_error(ArgumentError,/does not accept block/)
|
385
|
+
|
309
386
|
expect {
|
310
|
-
rendered.
|
387
|
+
expect(rendered).to have_tag('div') do
|
311
388
|
without_text 'sample text', proc { puts 'bla' }
|
312
389
|
end
|
313
390
|
}.to raise_error(ArgumentError)
|
314
391
|
end
|
315
392
|
|
316
393
|
it "should find tags" do
|
317
|
-
rendered.
|
394
|
+
expect(rendered).to have_tag('div') do
|
318
395
|
with_text 'sample text'
|
319
396
|
end
|
320
397
|
|
321
|
-
rendered.
|
398
|
+
expect(rendered).to have_tag('p') do
|
322
399
|
with_text 'one'
|
323
400
|
end
|
324
401
|
|
325
|
-
rendered.
|
402
|
+
expect(rendered).to have_tag('div') do
|
326
403
|
with_text /SAMPLE/i
|
327
404
|
end
|
328
405
|
|
329
|
-
rendered.
|
406
|
+
expect(rendered).to have_tag('span') do
|
330
407
|
with_text "sample with 'single' quotes"
|
331
408
|
end
|
332
409
|
|
333
|
-
rendered.
|
410
|
+
expect(rendered).to have_tag('span') do
|
334
411
|
with_text %Q{sample with 'single' and "double" quotes}
|
335
412
|
end
|
336
413
|
|
337
|
-
rendered.
|
414
|
+
expect(rendered).to have_tag('span') do
|
338
415
|
with_text /sample with 'single' and "double" quotes/
|
339
416
|
end
|
340
417
|
|
341
418
|
|
342
|
-
rendered.
|
419
|
+
expect(rendered).to have_tag('p') do
|
343
420
|
with_text 'content with nbsp'
|
344
421
|
end
|
345
422
|
|
346
|
-
rendered.
|
423
|
+
expect(rendered).to have_tag('pre') do
|
347
424
|
with_text " 1. bla \n 2. bla "
|
348
425
|
end
|
349
426
|
end
|
350
427
|
|
351
428
|
it "should not find tags" do
|
352
|
-
rendered.
|
429
|
+
expect(rendered).to have_tag('p') do
|
353
430
|
but_without_text 'text does not present'
|
354
431
|
without_text 'text does not present'
|
355
432
|
end
|
356
433
|
|
357
|
-
rendered.
|
434
|
+
expect(rendered).to have_tag('p') do
|
358
435
|
but_without_text /text does not present/
|
359
436
|
without_text /text does not present/
|
360
437
|
end
|
361
438
|
|
362
|
-
rendered.
|
439
|
+
expect(rendered).to have_tag('p') do
|
363
440
|
but_without_text 'contentwith nbsp'
|
364
441
|
without_text 'contentwith nbsp'
|
365
442
|
end
|
366
443
|
|
367
|
-
rendered.
|
444
|
+
expect(rendered).to have_tag('pre') do
|
368
445
|
but_without_text "1. bla\n2. bla"
|
369
446
|
without_text "1. bla\n2. bla"
|
370
447
|
end
|
@@ -372,14 +449,15 @@ describe 'have_tag' do
|
|
372
449
|
|
373
450
|
it "should not find tags and display appropriate message" do
|
374
451
|
expect {
|
375
|
-
rendered.
|
452
|
+
expect(rendered).to have_tag('div') do
|
376
453
|
with_text 'SAMPLE text'
|
377
454
|
end
|
378
455
|
}.to raise_spec_error(
|
379
456
|
%Q{"SAMPLE text" expected within "div" in following template:\n<div>sample text</div>}
|
380
457
|
)
|
458
|
+
|
381
459
|
expect {
|
382
|
-
rendered.
|
460
|
+
expect(rendered).to have_tag('div') do
|
383
461
|
with_text /SAMPLE tekzt/i
|
384
462
|
end
|
385
463
|
}.to raise_spec_error(
|
@@ -389,14 +467,15 @@ describe 'have_tag' do
|
|
389
467
|
|
390
468
|
it "should find unexpected tags and display appropriate message" do
|
391
469
|
expect {
|
392
|
-
rendered.
|
470
|
+
expect(rendered).to have_tag('div') do
|
393
471
|
without_text 'sample text'
|
394
472
|
end
|
395
473
|
}.to raise_spec_error(
|
396
474
|
%Q{"sample text" unexpected within "div" in following template:\n<div>sample text</div>\nbut was found.}
|
397
475
|
)
|
476
|
+
|
398
477
|
expect {
|
399
|
-
rendered.
|
478
|
+
expect(rendered).to have_tag('div') do
|
400
479
|
without_text /SAMPLE text/i
|
401
480
|
end
|
402
481
|
}.to raise_spec_error(
|
@@ -412,40 +491,40 @@ describe 'have_tag' do
|
|
412
491
|
asset 'special'
|
413
492
|
|
414
493
|
it "should find tags by count and exact content" do
|
415
|
-
rendered.
|
494
|
+
expect(rendered).to have_tag("td", :text => 'a', :count => 3)
|
416
495
|
end
|
417
496
|
|
418
497
|
it "should find tags by count and rough content(regexp)" do
|
419
|
-
rendered.
|
498
|
+
expect(rendered).to have_tag("td", :text => /user/, :count => 3)
|
420
499
|
end
|
421
500
|
|
422
501
|
it "should find tags with exact content and additional attributes" do
|
423
|
-
rendered.
|
424
|
-
rendered.
|
502
|
+
expect(rendered).to have_tag("td", :text => 'a', :with => { :id => "special" })
|
503
|
+
expect(rendered).to_not have_tag("td", :text => 'a', :with => { :id => "other-special" })
|
425
504
|
end
|
426
505
|
|
427
506
|
it "should find tags with rough content and additional attributes" do
|
428
|
-
rendered.
|
429
|
-
rendered.
|
507
|
+
expect(rendered).to have_tag("td", :text => /user/, :with => { :id => "other-special" })
|
508
|
+
expect(rendered).to_not have_tag("td", :text => /user/, :with => { :id => "special" })
|
430
509
|
end
|
431
510
|
|
432
511
|
it "should find tags with count and additional attributes" do
|
433
|
-
rendered.
|
434
|
-
rendered.
|
512
|
+
expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 6)
|
513
|
+
expect(rendered).to have_tag("div", :with => { :class => "two" }, :count => 3)
|
435
514
|
end
|
436
515
|
|
437
516
|
it "should find tags with count, exact text and additional attributes" do
|
438
|
-
rendered.
|
439
|
-
rendered.
|
440
|
-
rendered.
|
441
|
-
rendered.
|
517
|
+
expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'text')
|
518
|
+
expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => 'text')
|
519
|
+
expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'other text')
|
520
|
+
expect(rendered).to_not have_tag("div", :with => { :class => "two" }, :count => 3, :text => 'text')
|
442
521
|
end
|
443
522
|
|
444
523
|
it "should find tags with count, regexp text and additional attributes" do
|
445
|
-
rendered.
|
446
|
-
rendered.
|
447
|
-
rendered.
|
448
|
-
rendered.
|
524
|
+
expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 2, :text => /bla/)
|
525
|
+
expect(rendered).to have_tag("div", :with => { :class => "two" }, :count => 1, :text => /bla/)
|
526
|
+
expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => /bla/)
|
527
|
+
expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 6, :text => /other bla/)
|
449
528
|
end
|
450
529
|
end
|
451
530
|
|
@@ -453,7 +532,7 @@ describe 'have_tag' do
|
|
453
532
|
asset 'ordered_list'
|
454
533
|
|
455
534
|
it "should find tags" do
|
456
|
-
rendered.
|
535
|
+
expect(rendered).to have_tag('ol') {
|
457
536
|
with_tag('li', :text => 'list item 1')
|
458
537
|
with_tag('li', :text => 'list item 2')
|
459
538
|
with_tag('li', :text => 'list item 3')
|
@@ -465,7 +544,7 @@ describe 'have_tag' do
|
|
465
544
|
end
|
466
545
|
|
467
546
|
it "should not find tags" do
|
468
|
-
rendered.
|
547
|
+
expect(rendered).to have_tag('ol') {
|
469
548
|
without_tag('div')
|
470
549
|
without_tag('li', :count => 2)
|
471
550
|
without_tag('li', :count => 4..8)
|
@@ -478,7 +557,7 @@ describe 'have_tag' do
|
|
478
557
|
|
479
558
|
it "should handle do; end" do
|
480
559
|
expect {
|
481
|
-
rendered.
|
560
|
+
expect(rendered).to have_tag('ol') do
|
482
561
|
with_tag('div')
|
483
562
|
end
|
484
563
|
}.to raise_spec_error(/have at least 1 element matching "div", found 0/)
|
@@ -486,14 +565,17 @@ describe 'have_tag' do
|
|
486
565
|
|
487
566
|
it "should not find tags and display appropriate message" do
|
488
567
|
ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
|
568
|
+
|
489
569
|
expect {
|
490
|
-
rendered.
|
570
|
+
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('div') }
|
491
571
|
}.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have at least 1 element matching "div", found 0/)
|
572
|
+
|
492
573
|
expect {
|
493
|
-
rendered.
|
574
|
+
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
|
494
575
|
}.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have 10 element\(s\) matching "li", found 3/)
|
576
|
+
|
495
577
|
expect {
|
496
|
-
rendered.
|
578
|
+
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
|
497
579
|
}.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li" in following template:\n#{ordered_list_regexp}/)
|
498
580
|
end
|
499
581
|
end
|
@@ -504,7 +586,7 @@ describe 'have_tag' do
|
|
504
586
|
context "string as second argument" do
|
505
587
|
|
506
588
|
it "should map a string argument to :text => string" do
|
507
|
-
rendered.
|
589
|
+
expect(rendered).to have_tag('div', 'sample text')
|
508
590
|
end
|
509
591
|
|
510
592
|
end
|
@@ -512,11 +594,11 @@ describe 'have_tag' do
|
|
512
594
|
context "Regexp as second argument" do
|
513
595
|
|
514
596
|
it "should match against a valid Regexp" do
|
515
|
-
rendered.
|
597
|
+
expect(rendered).to have_tag('div', /sample\s/)
|
516
598
|
end
|
517
599
|
|
518
600
|
it "should not match against an invalid Regexp" do
|
519
|
-
rendered.
|
601
|
+
expect(rendered).to_not have_tag('div', /not matching/)
|
520
602
|
end
|
521
603
|
end
|
522
604
|
end
|