rspec-html-matchers 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,19 @@
1
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,153 +164,150 @@ 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/:seen 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
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
- unless Nokogiri::VERSION == '1.5.11'
299
- expect(rendered).to have_tag('p', :text => 'content with nbsp')
300
- end
301
- expect(rendered).to have_tag('pre', :text => " 1. bla \n 2. bla ")
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 ")
302
300
  end
303
301
 
304
- it "should find with unicode text specified" do
302
+ it 'should find with unicode text specified' do
305
303
  expect {
306
- expect(rendered).to have_tag('a', :text => "học")
304
+ expect(rendered).to have_tag('a', :text => 'học')
307
305
  }.not_to raise_error
308
306
 
309
- expect(rendered).to have_tag('a', :text => "học")
307
+ expect(rendered).to have_tag('a', :text => 'học')
310
308
  end
311
309
 
312
- it "should not find tags" do
310
+ it 'should not find tags' do
313
311
  expect(rendered).to_not have_tag('p', :text => 'text does not present')
314
312
  expect(rendered).to_not have_tag('strong', :text => 'text does not present')
315
313
  expect(rendered).to_not have_tag('p', :text => /text does not present/)
@@ -325,65 +323,63 @@ describe 'have_tag' do
325
323
  expect(rendered).to_not have_tag('pre', :text => "1. bla\n2. bla")
326
324
  end
327
325
 
328
- it "should invoke #to_s method for :text" do
326
+ it 'should invoke #to_s method for :text' do
329
327
  expect {
330
- expect(rendered).to_not have_tag('p', :text => 100500 )
331
- 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)
332
330
  }.to_not raise_exception
333
331
  end
334
332
 
335
- it "should not find tags and display appropriate message" do
336
- # TODO make diffable,maybe...
333
+ it 'should not find tags and display appropriate message' do
334
+ # TODO: make diffable,maybe...
337
335
  expect {
338
336
  expect(rendered).to have_tag('div', :text => 'SAMPLE text')
339
337
  }.to raise_spec_error(
340
- %Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
338
+ %("SAMPLE text" expected within "div" in following template:\n#{rendered})
341
339
  )
342
340
  expect {
343
341
  expect(rendered).to have_tag('div', :text => /SAMPLE tekzt/i)
344
342
  }.to raise_spec_error(
345
- %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})
346
344
  )
347
345
  end
348
346
 
349
- it "should find unexpected tags and display appropriate message" do
347
+ it 'should find unexpected tags and display appropriate message' do
350
348
  expect {
351
349
  expect(rendered).to_not have_tag('div', :text => 'sample text')
352
350
  }.to raise_spec_error(
353
- %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.)
354
352
  )
355
353
  expect {
356
354
  expect(rendered).to_not have_tag('div', :text => /SAMPLE text/i)
357
355
  }.to raise_spec_error(
358
- %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.)
359
357
  )
360
358
  end
361
-
362
359
  end
363
360
 
364
- context 'using alternative syntax(with_text/without_text)' do
365
-
366
- 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
367
363
  expect {
368
364
  with_text 'sample text'
369
- }.to raise_error(StandardError,/inside "have_tag"/)
365
+ }.to raise_error(StandardError, /inside "have_tag"/)
370
366
  expect {
371
367
  without_text 'sample text'
372
- }.to raise_error(StandardError,/inside "have_tag"/)
368
+ }.to raise_error(StandardError, /inside "have_tag"/)
373
369
  end
374
370
 
375
- it "should raise exception when used with block" do
371
+ it 'should raise exception when used with block' do
376
372
  expect {
377
373
  expect(rendered).to have_tag('div') do
378
374
  with_text 'sample text' do
379
375
  puts 'bla'
380
376
  end
381
377
  end
382
- }.to raise_error(ArgumentError,/does not accept block/)
378
+ }.to raise_error(ArgumentError, /does not accept block/)
383
379
 
384
380
  expect {
385
381
  expect(rendered).to have_tag('div') do
386
- with_text 'sample text', proc { puts 'bla' }
382
+ with_text('sample text', proc { puts 'bla' })
387
383
  end
388
384
  }.to raise_error(ArgumentError)
389
385
 
@@ -393,16 +389,16 @@ describe 'have_tag' do
393
389
  puts 'bla'
394
390
  end
395
391
  end
396
- }.to raise_error(ArgumentError,/does not accept block/)
392
+ }.to raise_error(ArgumentError, /does not accept block/)
397
393
 
398
394
  expect {
399
395
  expect(rendered).to have_tag('div') do
400
- without_text 'sample text', proc { puts 'bla' }
396
+ without_text('sample text', proc { puts 'bla' })
401
397
  end
402
398
  }.to raise_error(ArgumentError)
403
399
  end
404
400
 
405
- it "should find tags" do
401
+ it 'should find tags' do
406
402
  expect(rendered).to have_tag('div') do
407
403
  with_text 'sample text'
408
404
  end
@@ -420,7 +416,7 @@ describe 'have_tag' do
420
416
  end
421
417
 
422
418
  expect(rendered).to have_tag('span') do
423
- with_text %Q{sample with 'single' and "double" quotes}
419
+ with_text %(sample with 'single' and "double" quotes)
424
420
  end
425
421
 
426
422
  expect(rendered).to have_tag('span') do
@@ -438,7 +434,7 @@ describe 'have_tag' do
438
434
  end
439
435
  end
440
436
 
441
- it "should not find tags" do
437
+ it 'should not find tags' do
442
438
  expect(rendered).to have_tag('p') do
443
439
  but_without_text 'text does not present'
444
440
  without_text 'text does not present'
@@ -460,7 +456,7 @@ describe 'have_tag' do
460
456
  end
461
457
  end
462
458
 
463
- it "should not find tags and display appropriate message" do
459
+ it 'should not find tags and display appropriate message' do
464
460
  expect {
465
461
  expect(rendered).to have_tag('div') do
466
462
  with_text 'SAMPLE text'
@@ -478,13 +474,13 @@ describe 'have_tag' do
478
474
  )
479
475
  end
480
476
 
481
- it "should find unexpected tags and display appropriate message" do
477
+ it 'should find unexpected tags and display appropriate message' do
482
478
  expect {
483
479
  expect(rendered).to have_tag('div') do
484
480
  without_text 'sample text'
485
481
  end
486
482
  }.to raise_spec_error(
487
- %r{"sample text" unexpected within "div" in following template:}
483
+ /"sample text" unexpected within "div" in following template:/
488
484
  )
489
485
 
490
486
  expect {
@@ -495,56 +491,54 @@ describe 'have_tag' do
495
491
  %r{/SAMPLE text/i regexp unexpected within "div" in following template:}
496
492
  )
497
493
  end
498
-
499
494
  end
500
-
501
495
  end
502
496
 
503
- context "mixed matching" do
497
+ context '[mixed matching]' do
504
498
  asset 'special'
505
499
 
506
- it "should find tags by count and exact content" do
507
- 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)
508
502
  end
509
503
 
510
- it "should find tags by count and rough content(regexp)" do
511
- 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)
512
506
  end
513
507
 
514
- it "should find tags with exact content and additional attributes" do
515
- expect(rendered).to have_tag("td", :text => 'a', :with => { :id => "special" })
516
- 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' })
517
511
  end
518
512
 
519
- it "should find tags with rough content and additional attributes" do
520
- expect(rendered).to have_tag("td", :text => /user/, :with => { :id => "other-special" })
521
- 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' })
522
516
  end
523
517
 
524
- it "should find tags with count and additional attributes" do
525
- expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 6)
526
- 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)
527
521
  end
528
522
 
529
- it "should find tags with count, exact text and additional attributes" do
530
- expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'text')
531
- expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => 'text')
532
- expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'other text')
533
- 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')
534
528
  end
535
529
 
536
- it "should find tags with count, regexp text and additional attributes" do
537
- expect(rendered).to have_tag("div", :with => { :class => "one" }, :count => 2, :text => /bla/)
538
- expect(rendered).to have_tag("div", :with => { :class => "two" }, :count => 1, :text => /bla/)
539
- expect(rendered).to_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => /bla/)
540
- 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/)
541
535
  end
542
536
  end
543
537
 
544
- context "nested matching:" do
538
+ context '[nested matching]' do
545
539
  asset 'ordered_list'
546
540
 
547
- it "should find tags" do
541
+ it 'should find tags' do
548
542
  expect(rendered).to have_tag('ol') {
549
543
  with_tag('li', :text => 'list item 1')
550
544
  with_tag('li', :text => 'list item 2')
@@ -556,7 +550,7 @@ describe 'have_tag' do
556
550
  }
557
551
  end
558
552
 
559
- it "should not find tags" do
553
+ it 'should not find tags' do
560
554
  expect(rendered).to have_tag('ol') {
561
555
  without_tag('div')
562
556
  without_tag('li', :count => 2)
@@ -568,7 +562,7 @@ describe 'have_tag' do
568
562
  }
569
563
  end
570
564
 
571
- it "should handle do; end" do
565
+ it 'should handle do; end' do
572
566
  expect {
573
567
  expect(rendered).to have_tag('ol') do
574
568
  with_tag('div')
@@ -576,9 +570,7 @@ describe 'have_tag' do
576
570
  }.to raise_spec_error(/have at least 1 element matching "div", found 0/)
577
571
  end
578
572
 
579
- it "should not find tags and display appropriate message" do
580
- ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
581
-
573
+ it 'should not find tags and display appropriate message' do
582
574
  expect {
583
575
  expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('div') }
584
576
  }.to raise_spec_error(/to have at least 1 element matching "div", found 0/)
@@ -589,14 +581,14 @@ describe 'have_tag' do
589
581
 
590
582
  expect {
591
583
  expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
592
- }.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li"/)
584
+ }.to raise_spec_error(%r{/SAMPLE text/i regexp expected within "li"})
593
585
  end
594
586
  end
595
587
 
596
- context "deep nesting" do
588
+ context '[deep nesting]' do
597
589
  asset 'multiple_lists'
598
590
 
599
- it "should allow deep nesting" do
591
+ it 'should allow deep nesting' do
600
592
  expect(rendered).to have_tag('div') do
601
593
  with_tag 'ul.numeric' do
602
594
  with_tag 'li#one'
@@ -604,14 +596,14 @@ describe 'have_tag' do
604
596
  end
605
597
  end
606
598
 
607
- it "should clear context between nested tags" do
599
+ it 'should clear context between nested tags' do
608
600
  expect(rendered).to have_tag('div') do |div|
609
601
  expect(div).to have_tag 'ul.numeric'
610
602
  expect(div).to have_tag 'ul.alpha'
611
603
  end
612
604
  end
613
605
 
614
- it "should narrow context when deep nesting" do
606
+ it 'should narrow context when deep nesting' do
615
607
  expect do
616
608
  expect(rendered).to have_tag('div') do |div|
617
609
  expect(div).to have_tag 'ul.numeric' do |ul_numeric|
@@ -621,7 +613,7 @@ describe 'have_tag' do
621
613
  end .to raise_spec_error(/at least 1 element matching "li#aye", found 0/)
622
614
  end
623
615
 
624
- it "should narrow context for with_text" do
616
+ it 'should narrow context for with_text' do
625
617
  expect do
626
618
  expect(rendered).to have_tag('div') do |div|
627
619
  expect(div).to have_tag 'ul.numeric' do
@@ -632,7 +624,7 @@ describe 'have_tag' do
632
624
  end
633
625
  end
634
626
 
635
- context 'find nested tags' do
627
+ context '[find nested tags]' do
636
628
  asset 'nested_matchers'
637
629
 
638
630
  it 'with block parameters' do
@@ -658,27 +650,71 @@ describe 'have_tag' do
658
650
  end
659
651
  end
660
652
 
661
- context "backwards compatibility for unnamed arguments" do
653
+ context '[backwards compatibility for unnamed arguments]' do
662
654
  asset 'quotes'
663
655
 
664
- context "string as second argument" do
665
-
666
- it "should map a string argument to :text => string" do
656
+ context '[string as second argument]' do
657
+ it 'should map a string argument to :text => string' do
667
658
  expect(rendered).to have_tag('div', 'sample text')
668
659
  end
669
-
670
660
  end
671
661
 
672
- context "Regexp as second argument" do
673
-
674
- it "should match against a valid Regexp" do
662
+ context '[Regexp as second argument]' do
663
+ it 'should match against a valid Regexp' do
675
664
  expect(rendered).to have_tag('div', /sample\s/)
676
665
  end
677
666
 
678
- it "should not match against an invalid Regexp" do
679
- 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/)
680
669
  end
681
670
  end
682
671
  end
683
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
684
720
  end