rspec-html-matchers 0.7.0 → 0.10.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.
@@ -1,17 +1,19 @@
1
- # encoding: UTF-8
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 "through css selector" do
7
+ context '[through css selector]' do
6
8
  asset 'search_and_submit'
7
9
 
8
- it "should have right description" do
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 "should find tags" do
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 "should not find tags" do
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 "should not find tags and display appropriate message" do
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
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "span", found 0.}
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
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "span#some_id", found 0.}
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
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "span.some_class", found 0.}
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 "should find unexpected tags and display appropriate message" do
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
- %Q{expected following:\n#{rendered}\nto NOT have element matching "div", found 2.}
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
- %Q{expected following:\n#{rendered}\nto NOT have element matching "div#div", found 1.}
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
- %Q{expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.}
64
+ %(expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.)
63
65
  )
64
66
  end
65
67
 
66
- context "with additional HTML attributes(:with option)" do
67
- it "should find tags" do
68
- expect(rendered).to have_tag('input#search',:with => {:type => "text"})
69
- expect(rendered).to have_tag(:input ,:with => {:type => "submit", :value => "Save"})
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 "should find tags that have classes specified via array(or string)" do
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'})
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 "should not find tags that have classes specified via array" do
78
- expect(rendered).to_not have_tag('div',:with => {:class => %w(class-other class-two)})
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 "should not find tags that have classes specified via array and display appropriate message" do
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',:with => {:class => %w(class-other class-two)})
85
+ expect(rendered).to have_tag('div', :with => { :class => %w[class-other class-two] })
84
86
  }.to raise_spec_error(
85
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
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',:with => {:class => 'class-other class-two'})
90
+ expect(rendered).to have_tag('div', :with => { :class => 'class-other class-two' })
89
91
  }.to raise_spec_error(
90
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
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 "should not find tags" do
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"})
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 "should not find tags and display appropriate message" do
101
+ it 'should not find tags and display appropriate message' do
100
102
  expect {
101
- expect(rendered).to have_tag('input#search',:with => {:type => "some_other_type"})
103
+ expect(rendered).to have_tag('input#search', :with => { :type => 'some_other_type' })
102
104
  }.to raise_spec_error(
103
- %Q{expected following:\n#{rendered}\nto have at least 1 element matching "input#search[type='some_other_type']", found 0.}
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 "should find unexpected tags and display appropriate message" do
109
+ it 'should find unexpected tags and display appropriate message' do
108
110
  expect {
109
- expect(rendered).to_not have_tag('input#search',:with => {:type => "text"})
111
+ expect(rendered).to_not have_tag('input#search', :with => { :type => 'text' })
110
112
  }.to raise_spec_error(
111
- %Q{expected following:\n#{rendered}\nto NOT have element matching "input#search[type='text']", found 1.}
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 "with additional HTML attributes (:without option)" do
118
+ context '[with additional HTML attributes (:without option)]' do
118
119
  asset 'single_element'
119
120
 
120
- it "should find tags that have classes specified via array (or string)" do
121
- expect(rendered).to_not have_tag('div', :without => { :class => %w(foo bar) })
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 "should not find tags that have classes specified via array (or string)" do
128
- expect(rendered).to have_tag('div', :without => { :class => %w(foo baz) })
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 "by count" do
136
+ context '[by count]' do
136
137
  asset 'paragraphs'
137
138
 
138
- it "should have right description" do
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 "should find tags" do
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 "should find tags when :minimum specified" do
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 "should find tags when :maximum specified" do
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 "should not find tags(with :count, :minimum or :maximum specified)" do
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,215 +164,222 @@ describe 'have_tag' do
163
164
  expect(rendered).to_not have_tag('p', :maximum => 2)
164
165
  end
165
166
 
166
- it "should not find tags and display appropriate message(with :count)" do
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
- %Q{expected following:\n#{rendered}\nto have 10 element(s) matching "p", found 3.}
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
- %Q{expected following:\n#{rendered}\nto have at least 4 and at most 8 element(s) matching "p", found 3.}
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 "should find unexpected tags and display appropriate message(with :count)" do
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
- %Q{expected following:\n#{rendered}\nto NOT have 3 element(s) matching "p", but found.}
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
- %Q{expected following:\n#{rendered}\nto NOT have at least 1 and at most 3 element(s) matching "p", but found 3.}
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 "should not find tags and display appropriate message(with :minimum)" do
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
- %Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
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
- %Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
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 "should find unexpected tags and display appropriate message(with :minimum)" do
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
- %Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
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
- %Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
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 "should not find tags and display appropriate message(with :maximum)" do
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
- %Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
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
- %Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
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 "should find unexpected tags and display appropriate message(with :maximum)" do
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
- %Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
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
- %Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
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 "should raise error when wrong params specified" do
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
- wrong_params_error_msg_1 = ':count with :minimum or :maximum has no sence!'
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(wrong_params_error_msg_1)
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(wrong_params_error_msg_1)
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(wrong_params_error_msg_1)
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(wrong_params_error_msg_1)
266
+ }.to raise_error(wrong_params_error_msg1)
266
267
 
267
- wrong_params_error_msg_2 = ':minimum should be less than :maximum!'
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(wrong_params_error_msg_2)
272
+ }.to raise_error(wrong_params_error_msg2)
272
273
 
273
- [ 4..1, -2..6, 'a'..'z', 3..-9 ].each do |range|
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.to_s}) has no sence!")
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 "with :text specified" do
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 => %Q{sample with 'single' and "double" quotes})
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
- expect(rendered).to have_tag('p', :text => 'content with nbsp')
295
- expect(rendered).to have_tag('pre', :text => " 1. bla \n 2. bla ")
294
+ expect(rendered).to have_tag('p', :seen => 'content with ignored spaces around')
295
+ expect(rendered).to have_tag('p', :seen => 'content with ignored spaces in')
296
+ expect(rendered).to have_tag('p', :seen => 'content with nbsp  and  spaces   around')
297
+
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 ")
296
300
  end
297
301
 
298
- it "should find with unicode text specified" do
302
+ it 'should find with unicode text specified' do
299
303
  expect {
300
- expect(rendered).to have_tag('a', :text => "học")
304
+ expect(rendered).to have_tag('a', :text => 'học')
301
305
  }.not_to raise_error
302
306
 
303
- expect(rendered).to have_tag('a', :text => "học")
307
+ expect(rendered).to have_tag('a', :text => 'học')
304
308
  end
305
309
 
306
- it "should not find tags" do
310
+ it 'should not find tags' do
307
311
  expect(rendered).to_not have_tag('p', :text => 'text does not present')
308
312
  expect(rendered).to_not have_tag('strong', :text => 'text does not present')
309
313
  expect(rendered).to_not have_tag('p', :text => /text does not present/)
310
314
  expect(rendered).to_not have_tag('strong', :text => /text does not present/)
311
-
312
315
  expect(rendered).to_not have_tag('p', :text => 'contentwith nbsp')
316
+
317
+ expect(rendered).to_not have_tag('p', :seen => 'content with ignoredspaces around')
318
+ expect(rendered).to_not have_tag('p', :seen => 'content with ignored spaces around')
319
+ expect(rendered).to_not have_tag('p', :seen => 'content withignored spaces in')
320
+ expect(rendered).to_not have_tag('p', :seen => 'contentwith nbsp')
321
+ expect(rendered).to_not have_tag('p', :seen => 'content with nbsp and spaces around')
322
+
313
323
  expect(rendered).to_not have_tag('pre', :text => "1. bla\n2. bla")
314
324
  end
315
325
 
316
- it "should invoke #to_s method for :text" do
326
+ it 'should invoke #to_s method for :text' do
317
327
  expect {
318
- expect(rendered).to_not have_tag('p', :text => 100500 )
319
- 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)
320
330
  }.to_not raise_exception
321
331
  end
322
332
 
323
- it "should not find tags and display appropriate message" do
324
- # TODO make diffable,maybe...
333
+ it 'should not find tags and display appropriate message' do
334
+ # TODO: make diffable,maybe...
325
335
  expect {
326
336
  expect(rendered).to have_tag('div', :text => 'SAMPLE text')
327
337
  }.to raise_spec_error(
328
- %Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
338
+ %("SAMPLE text" expected within "div" in following template:\n#{rendered})
329
339
  )
330
340
  expect {
331
341
  expect(rendered).to have_tag('div', :text => /SAMPLE tekzt/i)
332
342
  }.to raise_spec_error(
333
- %Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered}}
343
+ %(/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered})
334
344
  )
335
345
  end
336
346
 
337
- it "should find unexpected tags and display appropriate message" do
347
+ it 'should find unexpected tags and display appropriate message' do
338
348
  expect {
339
349
  expect(rendered).to_not have_tag('div', :text => 'sample text')
340
350
  }.to raise_spec_error(
341
- %Q{"sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.}
351
+ %("sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.)
342
352
  )
343
353
  expect {
344
354
  expect(rendered).to_not have_tag('div', :text => /SAMPLE text/i)
345
355
  }.to raise_spec_error(
346
- %Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.}
356
+ %(/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.)
347
357
  )
348
358
  end
349
-
350
359
  end
351
360
 
352
- context 'using alternative syntax(with_text/without_text)' do
353
-
354
- 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
355
363
  expect {
356
364
  with_text 'sample text'
357
- }.to raise_error(StandardError,/inside "have_tag"/)
365
+ }.to raise_error(StandardError, /inside "have_tag"/)
358
366
  expect {
359
367
  without_text 'sample text'
360
- }.to raise_error(StandardError,/inside "have_tag"/)
368
+ }.to raise_error(StandardError, /inside "have_tag"/)
361
369
  end
362
370
 
363
- it "should raise exception when used with block" do
371
+ it 'should raise exception when used with block' do
364
372
  expect {
365
373
  expect(rendered).to have_tag('div') do
366
374
  with_text 'sample text' do
367
375
  puts 'bla'
368
376
  end
369
377
  end
370
- }.to raise_error(ArgumentError,/does not accept block/)
378
+ }.to raise_error(ArgumentError, /does not accept block/)
371
379
 
372
380
  expect {
373
381
  expect(rendered).to have_tag('div') do
374
- with_text 'sample text', proc { puts 'bla' }
382
+ with_text('sample text', proc { puts 'bla' })
375
383
  end
376
384
  }.to raise_error(ArgumentError)
377
385
 
@@ -381,16 +389,16 @@ describe 'have_tag' do
381
389
  puts 'bla'
382
390
  end
383
391
  end
384
- }.to raise_error(ArgumentError,/does not accept block/)
392
+ }.to raise_error(ArgumentError, /does not accept block/)
385
393
 
386
394
  expect {
387
395
  expect(rendered).to have_tag('div') do
388
- without_text 'sample text', proc { puts 'bla' }
396
+ without_text('sample text', proc { puts 'bla' })
389
397
  end
390
398
  }.to raise_error(ArgumentError)
391
399
  end
392
400
 
393
- it "should find tags" do
401
+ it 'should find tags' do
394
402
  expect(rendered).to have_tag('div') do
395
403
  with_text 'sample text'
396
404
  end
@@ -408,16 +416,17 @@ describe 'have_tag' do
408
416
  end
409
417
 
410
418
  expect(rendered).to have_tag('span') do
411
- with_text %Q{sample with 'single' and "double" quotes}
419
+ with_text %(sample with 'single' and "double" quotes)
412
420
  end
413
421
 
414
422
  expect(rendered).to have_tag('span') do
415
423
  with_text /sample with 'single' and "double" quotes/
416
424
  end
417
425
 
418
-
419
- expect(rendered).to have_tag('p') do
420
- with_text 'content with nbsp'
426
+ unless Nokogiri::VERSION == '1.5.11'
427
+ expect(rendered).to have_tag('p') do
428
+ with_text 'content with nbsp'
429
+ end
421
430
  end
422
431
 
423
432
  expect(rendered).to have_tag('pre') do
@@ -425,7 +434,7 @@ describe 'have_tag' do
425
434
  end
426
435
  end
427
436
 
428
- it "should not find tags" do
437
+ it 'should not find tags' do
429
438
  expect(rendered).to have_tag('p') do
430
439
  but_without_text 'text does not present'
431
440
  without_text 'text does not present'
@@ -447,13 +456,13 @@ describe 'have_tag' do
447
456
  end
448
457
  end
449
458
 
450
- it "should not find tags and display appropriate message" do
459
+ it 'should not find tags and display appropriate message' do
451
460
  expect {
452
461
  expect(rendered).to have_tag('div') do
453
462
  with_text 'SAMPLE text'
454
463
  end
455
464
  }.to raise_spec_error(
456
- %Q{"SAMPLE text" expected within "div" in following template:\n<div>sample text</div>}
465
+ /"SAMPLE text" expected within "div" in following template:/
457
466
  )
458
467
 
459
468
  expect {
@@ -461,17 +470,17 @@ describe 'have_tag' do
461
470
  with_text /SAMPLE tekzt/i
462
471
  end
463
472
  }.to raise_spec_error(
464
- %Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n<div>sample text</div>}
473
+ %r{/SAMPLE tekzt/i regexp expected within "div" in following template:}
465
474
  )
466
475
  end
467
476
 
468
- it "should find unexpected tags and display appropriate message" do
477
+ it 'should find unexpected tags and display appropriate message' do
469
478
  expect {
470
479
  expect(rendered).to have_tag('div') do
471
480
  without_text 'sample text'
472
481
  end
473
482
  }.to raise_spec_error(
474
- %Q{"sample text" unexpected within "div" in following template:\n<div>sample text</div>\nbut was found.}
483
+ /"sample text" unexpected within "div" in following template:/
475
484
  )
476
485
 
477
486
  expect {
@@ -479,59 +488,57 @@ describe 'have_tag' do
479
488
  without_text /SAMPLE text/i
480
489
  end
481
490
  }.to raise_spec_error(
482
- %Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n<div>sample text</div>\nbut was found.}
491
+ %r{/SAMPLE text/i regexp unexpected within "div" in following template:}
483
492
  )
484
493
  end
485
-
486
494
  end
487
-
488
495
  end
489
496
 
490
- context "mixed matching" do
497
+ context '[mixed matching]' do
491
498
  asset 'special'
492
499
 
493
- it "should find tags by count and exact content" do
494
- expect(rendered).to have_tag("td", :text => 'a', :count => 3)
500
+ it 'should find tags by count and exact content' do
501
+ expect(rendered).to have_tag('td', :text => 'a', :count => 3)
495
502
  end
496
503
 
497
- it "should find tags by count and rough content(regexp)" do
498
- expect(rendered).to have_tag("td", :text => /user/, :count => 3)
504
+ it 'should find tags by count and rough content(regexp)' do
505
+ expect(rendered).to have_tag('td', :text => /user/, :count => 3)
499
506
  end
500
507
 
501
- it "should find tags with exact content and additional attributes" do
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" })
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' })
504
511
  end
505
512
 
506
- it "should find tags with rough content and additional attributes" do
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" })
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' })
509
516
  end
510
517
 
511
- it "should find tags with count and additional attributes" do
512
- expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 6)
513
- expect(rendered).to have_tag("div", :with => { :class => "two" }, :count => 3)
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)
514
521
  end
515
522
 
516
- it "should find tags with count, exact text and additional attributes" do
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')
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')
521
528
  end
522
529
 
523
- it "should find tags with count, regexp text and additional attributes" do
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/)
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/)
528
535
  end
529
536
  end
530
537
 
531
- context "nested matching:" do
538
+ context '[nested matching]' do
532
539
  asset 'ordered_list'
533
540
 
534
- it "should find tags" do
541
+ it 'should find tags' do
535
542
  expect(rendered).to have_tag('ol') {
536
543
  with_tag('li', :text => 'list item 1')
537
544
  with_tag('li', :text => 'list item 2')
@@ -543,7 +550,7 @@ describe 'have_tag' do
543
550
  }
544
551
  end
545
552
 
546
- it "should not find tags" do
553
+ it 'should not find tags' do
547
554
  expect(rendered).to have_tag('ol') {
548
555
  without_tag('div')
549
556
  without_tag('li', :count => 2)
@@ -555,7 +562,7 @@ describe 'have_tag' do
555
562
  }
556
563
  end
557
564
 
558
- it "should handle do; end" do
565
+ it 'should handle do; end' do
559
566
  expect {
560
567
  expect(rendered).to have_tag('ol') do
561
568
  with_tag('div')
@@ -563,44 +570,151 @@ describe 'have_tag' do
563
570
  }.to raise_spec_error(/have at least 1 element matching "div", found 0/)
564
571
  end
565
572
 
566
- it "should not find tags and display appropriate message" do
567
- ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
568
-
573
+ it 'should not find tags and display appropriate message' do
569
574
  expect {
570
575
  expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('div') }
571
- }.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have at least 1 element matching "div", found 0/)
576
+ }.to raise_spec_error(/to have at least 1 element matching "div", found 0/)
572
577
 
573
578
  expect {
574
579
  expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
575
- }.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have 10 element\(s\) matching "li", found 3/)
580
+ }.to raise_spec_error(/to have 10 element\(s\) matching "li", found 3/)
576
581
 
577
582
  expect {
578
583
  expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
579
- }.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li" in following template:\n#{ordered_list_regexp}/)
584
+ }.to raise_spec_error(%r{/SAMPLE text/i regexp expected within "li"})
580
585
  end
581
586
  end
582
587
 
583
- context "backwards compatibility for unnamed arguments" do
584
- asset 'quotes'
588
+ context '[deep nesting]' do
589
+ asset 'multiple_lists'
590
+
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
585
598
 
586
- context "string as second argument" do
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
587
605
 
588
- it "should map a string argument to :text => string" do
589
- expect(rendered).to have_tag('div', 'sample text')
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
590
638
  end
639
+ end
591
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
592
650
  end
651
+ end
593
652
 
594
- context "Regexp as second argument" do
653
+ context '[backwards compatibility for unnamed arguments]' do
654
+ asset 'quotes'
655
+
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
595
661
 
596
- it "should match against a valid Regexp" do
662
+ context '[Regexp as second argument]' do
663
+ it 'should match against a valid Regexp' do
597
664
  expect(rendered).to have_tag('div', /sample\s/)
598
665
  end
599
666
 
600
- it "should not match against an invalid Regexp" do
601
- expect(rendered).to_not have_tag('div', /not matching/)
667
+ it 'should not match against an invalid Regexp' do
668
+ expect(rendered).to_not have_tag('div', /not matching/)
602
669
  end
603
670
  end
604
671
  end
605
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
606
720
  end