rails-dom-testing 2.0.3 → 2.3.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,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
- require 'test_helper'
4
- require 'rails/dom/testing/assertions/selector_assertions'
4
+ require "test_helper"
5
5
 
6
6
  class AssertSelectTest < ActiveSupport::TestCase
7
7
  Assertion = Minitest::Assertion
8
8
 
9
+ include DomTestingHelpers
9
10
  include Rails::Dom::Testing::Assertions::SelectorAssertions
10
11
 
11
12
  def assert_failure(message, &block)
@@ -15,23 +16,23 @@ class AssertSelectTest < ActiveSupport::TestCase
15
16
  end
16
17
 
17
18
  #
18
- # Test assert select.
19
+ # Test assert_select.
19
20
  #
20
21
 
21
22
  def test_assert_select
22
- render_html %Q{<div id="1"></div><div id="2"></div>}
23
+ render_html '<div id="1"></div><div id="2"></div>'
23
24
  assert_select "div", 2
24
- assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" }
25
+ assert_failure(/Expected at least 1 element matching "p", found 0/) { assert_select "p" }
25
26
  end
26
27
 
27
28
  def test_equality_integer
28
- render_html %Q{<div id="1"></div><div id="2"></div>}
29
- assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) { assert_select "div", 3 }
30
- assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", 0 }
29
+ render_html '<div id="1"></div><div id="2"></div>'
30
+ assert_failure(/Expected exactly 3 elements matching "div", found 2/) { assert_select "div", 3 }
31
+ assert_failure(/Expected exactly 0 elements matching "div", found 2/) { assert_select "div", 0 }
31
32
  end
32
33
 
33
34
  def test_equality_true_false
34
- render_html %Q{<div id="1"></div><div id="2"></div>}
35
+ render_html '<div id="1"></div><div id="2"></div>'
35
36
  assert_nothing_raised { assert_select "div" }
36
37
  assert_raise(Assertion) { assert_select "p" }
37
38
  assert_nothing_raised { assert_select "div", true }
@@ -49,21 +50,21 @@ class AssertSelectTest < ActiveSupport::TestCase
49
50
  end
50
51
 
51
52
  def test_equality_false_message
52
- render_html %Q{<div id="1"></div><div id="2"></div>}
53
- assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", false }
53
+ render_html '<div id="1"></div><div id="2"></div>'
54
+ assert_failure(/Expected exactly 0 elements matching "div", found 2/) { assert_select "div", false }
54
55
  end
55
56
 
56
57
  def test_equality_string_and_regexp
57
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
58
+ render_html '<div id="1">foo</div><div id="2">foo</div>'
58
59
  assert_nothing_raised { assert_select "div", "foo" }
59
60
  assert_raise(Assertion) { assert_select "div", "bar" }
60
- assert_nothing_raised { assert_select "div", :text=>"foo" }
61
- assert_raise(Assertion) { assert_select "div", :text=>"bar" }
61
+ assert_nothing_raised { assert_select "div", text: "foo" }
62
+ assert_raise(Assertion) { assert_select "div", text: "bar" }
62
63
  assert_nothing_raised { assert_select "div", /(foo|bar)/ }
63
64
  assert_raise(Assertion) { assert_select "div", /foobar/ }
64
- assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
65
- assert_raise(Assertion) { assert_select "div", :text=>/foobar/ }
66
- assert_raise(Assertion) { assert_select "p", :text=>/foobar/ }
65
+ assert_nothing_raised { assert_select "div", text: /(foo|bar)/ }
66
+ assert_raise(Assertion) { assert_select "div", text: /foobar/ }
67
+ assert_raise(Assertion) { assert_select "p", text: /foobar/ }
67
68
  end
68
69
 
69
70
  def test_equality_of_html
@@ -72,57 +73,70 @@ class AssertSelectTest < ActiveSupport::TestCase
72
73
  html = "<em>\"This is <strong>not</strong> a big problem,\"</em> he said."
73
74
  assert_nothing_raised { assert_select "p", text }
74
75
  assert_raise(Assertion) { assert_select "p", html }
75
- assert_nothing_raised { assert_select "p", :html=>html }
76
- assert_raise(Assertion) { assert_select "p", :html=>text }
76
+ assert_nothing_raised { assert_select "p", html: html }
77
+ assert_raise(Assertion) { assert_select "p", html: text }
77
78
  # No stripping for pre.
78
79
  render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
79
80
  text = "\n\"This is not a big problem,\" he said.\n"
80
81
  html = "\n<em>\"This is <strong>not</strong> a big problem,\"</em> he said.\n"
81
82
  assert_nothing_raised { assert_select "pre", text }
82
83
  assert_raise(Assertion) { assert_select "pre", html }
83
- assert_nothing_raised { assert_select "pre", :html=>html }
84
- assert_raise(Assertion) { assert_select "pre", :html=>text }
84
+ assert_nothing_raised { assert_select "pre", html: html }
85
+ assert_raise(Assertion) { assert_select "pre", html: text }
85
86
  end
86
87
 
87
88
  def test_strip_textarea
88
- render_html %Q{<textarea>\n\nfoo\n</textarea>}
89
+ render_html "<textarea>\n\nfoo\n</textarea>"
89
90
  assert_select "textarea", "\nfoo\n"
90
- render_html %Q{<textarea>\nfoo</textarea>}
91
+ render_html "<textarea>\nfoo</textarea>"
91
92
  assert_select "textarea", "foo"
92
93
  end
93
94
 
94
95
  def test_counts
95
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
96
+ render_html '<div id="1">foo</div><div id="2">foo</div>'
96
97
  assert_nothing_raised { assert_select "div", 2 }
97
- assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do
98
+ assert_failure(/Expected exactly 3 elements matching "div", found 2/) do
98
99
  assert_select "div", 3
99
100
  end
100
101
  assert_nothing_raised { assert_select "div", 1..2 }
101
- assert_failure(/Expected between 3 and 4 elements matching \"div\", found 2/) do
102
+ assert_failure(/Expected between 3 and 4 elements matching "div", found 2/) do
102
103
  assert_select "div", 3..4
103
104
  end
104
- assert_nothing_raised { assert_select "div", :count=>2 }
105
- assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do
106
- assert_select "div", :count=>3
105
+ assert_nothing_raised { assert_select "div", count: 2 }
106
+ assert_failure(/Expected exactly 3 elements matching "div", found 2/) do
107
+ assert_select "div", count: 3
107
108
  end
108
- assert_nothing_raised { assert_select "div", :minimum=>1 }
109
- assert_nothing_raised { assert_select "div", :minimum=>2 }
110
- assert_failure(/Expected at least 3 elements matching \"div\", found 2/) do
111
- assert_select "div", :minimum=>3
109
+ assert_nothing_raised { assert_select "div", minimum: 1 }
110
+ assert_nothing_raised { assert_select "div", minimum: 2 }
111
+ assert_failure(/Expected at least 3 elements matching "div", found 2/) do
112
+ assert_select "div", minimum: 3
112
113
  end
113
- assert_nothing_raised { assert_select "div", :maximum=>2 }
114
- assert_nothing_raised { assert_select "div", :maximum=>3 }
115
- assert_failure(/Expected at most 1 element matching \"div\", found 2/) do
116
- assert_select "div", :maximum=>1
114
+ assert_nothing_raised { assert_select "div", maximum: 2 }
115
+ assert_nothing_raised { assert_select "div", maximum: 3 }
116
+ assert_failure(/Expected at most 1 element matching "div", found 2/) do
117
+ assert_select "div", maximum: 1
117
118
  end
118
- assert_nothing_raised { assert_select "div", :minimum=>1, :maximum=>2 }
119
- assert_failure(/Expected between 3 and 4 elements matching \"div\", found 2/) do
120
- assert_select "div", :minimum=>3, :maximum=>4
119
+ assert_nothing_raised { assert_select "div", minimum: 1, maximum: 2 }
120
+ assert_failure(/Expected between 3 and 4 elements matching "div", found 2/) do
121
+ assert_select "div", minimum: 3, maximum: 4
121
122
  end
122
123
  end
123
124
 
125
+ def test_zero_counts_with_block
126
+ render_html "<div>foo</div>"
127
+
128
+ errors = [
129
+ assert_raises(ArgumentError) { assert_select("p", false) { nil } },
130
+ assert_raises(ArgumentError) { assert_select("p", 0) { nil } },
131
+ assert_raises(ArgumentError) { assert_select("p", count: 0) { nil } },
132
+ assert_raises(ArgumentError) { assert_select("p", 0..0) { nil } },
133
+ assert_raises(ArgumentError) { assert_select("p", minimum: 0, maximum: 0) { nil } }
134
+ ]
135
+ assert_equal ["Cannot be called with a block when asserting that a selector does not match"], errors.map(&:message).uniq
136
+ end
137
+
124
138
  def test_substitution_values
125
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
139
+ render_html '<div id="1">foo</div><div id="2">foo</div>'
126
140
  assert_select "div:match('id', ?)", /\d+/ do |elements|
127
141
  assert_equal 2, elements.size
128
142
  end
@@ -135,20 +149,40 @@ class AssertSelectTest < ActiveSupport::TestCase
135
149
  end
136
150
  end
137
151
 
152
+ def test_substitution_value_with_quotes
153
+ render_html '<input placeholder="placeholder with &quot;quotes&quot;" />'
154
+ assert_select "input[placeholder=?]", 'placeholder with "quotes"'
155
+ end
156
+
157
+ def test_multiple_substitution_values
158
+ render_html '<input name="foo[12]" value="34">'
159
+ assert_select ":match('name', ?):match('value', ?)", /\w+\[\d+\]/, /\d+/
160
+ end
161
+
162
+ def test_substitution_values_with_values_other_than_string_or_regexp
163
+ render_html '<div id="id_string">symbol</div><div id="1">numeric</div>'
164
+ assert_select "div:match('id', ?)", :id_string do |elements|
165
+ assert_equal 1, elements.size
166
+ end
167
+ assert_select "div:match('id', ?)", 1 do |elements|
168
+ assert_equal 1, elements.size
169
+ end
170
+ end
171
+
138
172
  def test_assert_select_root_html
139
- render_html '<a></a>'
173
+ render_html "<a></a>"
140
174
 
141
- assert_select 'a'
175
+ assert_select "a"
142
176
  end
143
177
 
144
178
  def test_assert_select_root_xml
145
179
  render_xml '<rss version="2.0"></rss>'
146
180
 
147
- assert_select 'rss'
181
+ assert_select "rss"
148
182
  end
149
183
 
150
184
  def test_nested_assert_select
151
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
185
+ render_html '<div id="1">foo</div><div id="2">foo</div>'
152
186
  assert_select "div" do |elements|
153
187
  assert_equal 2, elements.size
154
188
  assert_select elements, "#1"
@@ -166,7 +200,7 @@ class AssertSelectTest < ActiveSupport::TestCase
166
200
  end
167
201
  end
168
202
 
169
- assert_failure(/Expected at least 1 element matching \"#4\", found 0\./) do
203
+ assert_failure(/Expected at least 1 element matching "#4", found 0\./) do
170
204
  assert_select "div" do
171
205
  assert_select "#4"
172
206
  end
@@ -174,19 +208,128 @@ class AssertSelectTest < ActiveSupport::TestCase
174
208
  end
175
209
 
176
210
  def test_assert_select_text_match
177
- render_html %Q{<div id="1"><span>foo</span></div><div id="2"><span>bar</span></div>}
211
+ render_html '<div id="1"><span>foo</span></div><div id="2"><span>bar</span></div>'
178
212
  assert_select "div" do
179
213
  assert_nothing_raised { assert_select "div", "foo" }
180
214
  assert_nothing_raised { assert_select "div", "bar" }
181
215
  assert_nothing_raised { assert_select "div", /\w*/ }
182
- assert_nothing_raised { assert_select "div", :text => /\w*/, :count=>2 }
183
- assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
184
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
185
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
186
- assert_nothing_raised { assert_select "div", :html=>/\w*/ }
187
- assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
188
- assert_raise(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
216
+ assert_nothing_raised { assert_select "div", text: /\w*/, count: 2 }
217
+ assert_raise(Assertion) { assert_select "div", text: "foo", count: 2 }
218
+ assert_nothing_raised { assert_select "div", html: "<span>bar</span>" }
219
+ assert_nothing_raised { assert_select "div", html: "<span>bar</span>" }
220
+ assert_nothing_raised { assert_select "div", html: /\w*/ }
221
+ assert_nothing_raised { assert_select "div", html: /\w*/, count: 2 }
222
+ assert_raise(Assertion) { assert_select "div", html: "<span>foo</span>", count: 2 }
223
+ end
224
+ end
225
+
226
+ def test_assert_select_with_invalid_range
227
+ render_html "<div>foo</div>"
228
+ error = assert_raises(ArgumentError) { assert_select("div", 2..1) { nil } }
229
+ assert_equal "Range begin or :minimum cannot be greater than Range end or :maximum", error.message
230
+ end
231
+
232
+ def test_assert_select_with_invalid_minimum_and_maximum
233
+ render_html "<div>foo</div>"
234
+ error = assert_raises(ArgumentError) { assert_select("div", maximum: 0) { nil } }
235
+ assert_equal "Range begin or :minimum cannot be greater than Range end or :maximum", error.message
236
+ error = assert_raises(ArgumentError) { assert_select("div", minimum: 2, maximum: 1) { nil } }
237
+ assert_equal "Range begin or :minimum cannot be greater than Range end or :maximum", error.message
238
+ end
239
+
240
+ def test_assert_select_text_equality_collapses_whitespace
241
+ render_html "<p>Some\n line-broken\n text</p>"
242
+
243
+ assert_nothing_raised do
244
+ assert_select "p", {
245
+ text: "Some line-broken text",
246
+ }, "Whitespace was not collapsed from text"
189
247
  end
248
+
249
+ render_html "<p>Some<br><br>line-broken<br><br>text</p>"
250
+
251
+ assert_nothing_raised do
252
+ assert_select "p", {
253
+ text: "Someline-brokentext",
254
+ }, "<br> was not removed from text"
255
+ end
256
+ end
257
+
258
+ def test_assert_select_html_equality_respects_whitespace
259
+ render_html "<p>Some\n line-broken\n text</p>"
260
+
261
+ assert_nothing_raised do
262
+ assert_select "p", {
263
+ html: "Some\n line-broken\n text",
264
+ }, "Whitespace was collapsed from html"
265
+ end
266
+
267
+ render_html "<p>Some<br><br>line-broken<br><br>text</p>"
268
+
269
+ assert_nothing_raised do
270
+ assert_select "p", {
271
+ html: "Some<br><br>line-broken<br><br>text",
272
+ }, "<br> was removed from html"
273
+ end
274
+ end
275
+
276
+ #
277
+ # Test assert_not_select.
278
+ #
279
+
280
+ def test_assert_not_select
281
+ render_html '<div id="1"></div>'
282
+ assert_not_select "p"
283
+ assert_failure(/Expected exactly 0 elements matching "div", found 1/) { assert_not_select "div" }
284
+ assert_failure(/Expected exactly 0 elements matching "div#1", found 1/) { assert_not_select "div#1" }
285
+ end
286
+
287
+ def test_assert_not_select_with_true
288
+ render_html '<div id="1"></div>'
289
+ error = assert_raises(ArgumentError) { assert_not_select "div", true }
290
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
291
+ end
292
+
293
+ def test_assert_not_select_with_false
294
+ render_html '<div id="1"></div>'
295
+ error = assert_raises(ArgumentError) { assert_not_select "div", false }
296
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
297
+ end
298
+
299
+ def test_assert_not_select_with_integer
300
+ render_html '<div id="1"></div>'
301
+ error = assert_raises(ArgumentError) { assert_not_select "div", 1 }
302
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
303
+ end
304
+
305
+ def test_assert_not_select_with_range
306
+ render_html '<div id="1"></div>'
307
+ error = assert_raises(ArgumentError) { assert_not_select "div", 1..5 }
308
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
309
+ end
310
+
311
+ def test_assert_not_select_with_count
312
+ render_html '<div id="1"></div>'
313
+ error = assert_raises(ArgumentError) { assert_not_select "div", count: 1 }
314
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
315
+ end
316
+
317
+ def test_assert_not_select_with_minimum
318
+ render_html '<div id="1"></div>'
319
+ error = assert_raises(ArgumentError) { assert_not_select "div", minimum: 1 }
320
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
321
+ end
322
+
323
+ def test_assert_not_select_with_maximum
324
+ render_html '<div id="1"></div>'
325
+ error = assert_raises(ArgumentError) { assert_not_select "div", maximum: 1 }
326
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match", error.message
327
+ end
328
+
329
+ def test_assert_not_select_with_block
330
+ render_html "<div>foo</div>"
331
+ error = assert_raises(ArgumentError) { assert_not_select("p") { nil } }
332
+ assert_equal "Cannot be called with a block when asserting that a selector does not match", error.message
190
333
  end
191
334
 
192
335
  #
@@ -194,13 +337,13 @@ class AssertSelectTest < ActiveSupport::TestCase
194
337
  #
195
338
 
196
339
  def test_css_select
197
- render_html %Q{<div id="1"></div><div id="2"></div>}
340
+ render_html '<div id="1"></div><div id="2"></div>'
198
341
  assert_equal 2, css_select("div").size
199
342
  assert_equal 0, css_select("p").size
200
343
  end
201
344
 
202
345
  def test_nested_css_select
203
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
346
+ render_html '<div id="1">foo</div><div id="2">foo</div>'
204
347
  assert_select "div:match('id', ?)", /\d+/ do |elements|
205
348
  assert_equal 1, css_select(elements[0], "div").size
206
349
  assert_equal 1, css_select(elements[1], "div").size
@@ -209,10 +352,10 @@ class AssertSelectTest < ActiveSupport::TestCase
209
352
  assert_equal 2, css_select("div").size
210
353
  css_select("div").each do |element|
211
354
  # Testing as a group is one thing
212
- assert !css_select("#1,#2").empty?
355
+ assert_not css_select("#1,#2").empty?
213
356
  # Testing individually is another
214
- assert !css_select("#1").empty?
215
- assert !css_select("#2").empty?
357
+ assert_not css_select("#1").empty?
358
+ assert_not css_select("#2").empty?
216
359
  end
217
360
  end
218
361
  end
@@ -233,13 +376,13 @@ class AssertSelectTest < ActiveSupport::TestCase
233
376
  end
234
377
 
235
378
  def test_nested_assert_select_with_match_failure_shows_nice_regex
236
- render_html %Q{<div id="1">foo</div>}
379
+ render_html '<div id="1">foo</div>'
237
380
 
238
381
  error = assert_raises Minitest::Assertion do
239
382
  assert_select "div:match('id', ?)", /wups/
240
383
  end
241
384
 
242
- assert_match %Q{div:match('id', /wups/)}, error.message
385
+ assert_match "div:match('id', /wups/)", error.message
243
386
  end
244
387
 
245
388
  def test_feed_item_encoded
@@ -260,12 +403,11 @@ class AssertSelectTest < ActiveSupport::TestCase
260
403
  </item>
261
404
  </channel>
262
405
  </rss>
263
- EOF
406
+ EOF
264
407
 
265
408
  assert_select "channel item description" do
266
-
267
409
  assert_select_encoded do
268
- assert_select "p", :count=>2, :text=>/Test/
410
+ assert_select "p", count: 2, text: /Test/
269
411
  end
270
412
 
271
413
  # Test individually.
@@ -287,19 +429,83 @@ EOF
287
429
  end
288
430
  end
289
431
 
432
+ def test_feed_item_encoded_with_html_version
433
+ # https://html.spec.whatwg.org/multipage/parsing.html#an-introduction-to-error-handling-and-strange-cases-in-the-parser
434
+ # we use these results to assert that we're invoking the expected parser.
435
+ input = CGI.escapeHTML("<p>1<b>2<i>3</b>4</i>5</p>")
436
+ html4_result = jruby? ? "<p>1<b>2<i>3</i></b><i>4</i>5</p>" : "<p>1<b>2<i>3</i></b>45</p>"
437
+ html5_result = jruby? ? nil : "<p>1<b>2<i>3</i></b><i>4</i>5</p>"
438
+
439
+ render_xml(<<~XML)
440
+ <root>
441
+ <contents>#{input}</contents>
442
+ </root>
443
+ XML
444
+
445
+ with_default_html_version(:html4) do
446
+ assert_select "root contents" do
447
+ assert_select_encoded do |contents|
448
+ assert_equal(html4_result, contents.to_html)
449
+ end
450
+
451
+ assert_select_encoded(html_version: :html4) do |contents|
452
+ assert_equal(html4_result, contents.to_html)
453
+ end
454
+
455
+ assert_select_encoded(html_version: :html5) do |contents|
456
+ assert_equal(html5_result, contents.to_html)
457
+ end if Rails::Dom::Testing.html5_support?
458
+ end
459
+ end
460
+
461
+ with_default_html_version(:html5) do
462
+ assert_select "root contents" do
463
+ assert_select_encoded do |contents|
464
+ assert_equal(html5_result, contents.to_html)
465
+ end if Rails::Dom::Testing.html5_support?
466
+
467
+ assert_select_encoded(html_version: :html4) do |contents|
468
+ assert_equal(html4_result, contents.to_html)
469
+ end
470
+
471
+ assert_select_encoded(html_version: :html5) do |contents|
472
+ assert_equal(html5_result, contents.to_html)
473
+ end if Rails::Dom::Testing.html5_support?
474
+ end
475
+ end
476
+ end
477
+
290
478
  def test_body_not_present_in_empty_document
291
- render_html '<div></div>'
292
- assert_select 'body', 0
479
+ render_html "<div></div>"
480
+ assert_select "body", 0
293
481
  end
294
482
 
295
483
  def test_body_class_can_be_tested
296
484
  render_html '<body class="foo"></body>'
297
- assert_select '.foo'
485
+ assert_select ".foo"
298
486
  end
299
487
 
300
488
  def test_body_class_can_be_tested_with_html
301
489
  render_html '<html><body class="foo"><div></div></body></html>'
302
- assert_select '.foo'
490
+ assert_select ".foo"
491
+ end
492
+
493
+ def test_assert_select_with_extra_argument
494
+ render_html "<html><head><title>Welcome</title></head><body><div></div></body></html>"
495
+
496
+ assert_raises ArgumentError do
497
+ assert_select "title", "Welcome", count: 1
498
+ end
499
+
500
+ assert_select "title", text: "Welcome", count: 1
501
+ end
502
+
503
+ def test_assert_select_on_blank_response
504
+ render_html ""
505
+ assert_select "div", 0
506
+ assert_failure(/Expected exactly 1 element matching "div", found 0./) do
507
+ assert_select "div", 1
508
+ end
303
509
  end
304
510
 
305
511
  protected
@@ -315,7 +521,7 @@ EOF
315
521
  @html_document = if content_type == :xml
316
522
  Nokogiri::XML::Document.parse(content)
317
523
  else
318
- Nokogiri::HTML::Document.parse(content)
524
+ Rails::Dom::Testing.html_document.parse(content)
319
525
  end
320
526
  end
321
527
 
data/test/test_helper.rb CHANGED
@@ -1,6 +1,23 @@
1
- require 'nokogiri'
2
- require 'active_support'
3
- require 'active_support/test_case'
4
- require 'minitest/autorun'
1
+ # frozen_string_literal: true
2
+
3
+ require "rails-dom-testing"
4
+ require "active_support/test_case"
5
+ require "minitest/autorun"
5
6
 
6
7
  ActiveSupport::TestCase.test_order = :random
8
+
9
+ module DomTestingHelpers
10
+ def jruby?
11
+ !! Nokogiri.jruby?
12
+ end
13
+
14
+ def with_default_html_version(version)
15
+ old_version = Rails::Dom::Testing.default_html_version
16
+ begin
17
+ Rails::Dom::Testing.default_html_version = version
18
+ yield
19
+ ensure
20
+ Rails::Dom::Testing.default_html_version = old_version
21
+ end
22
+ end
23
+ end