Skip to content

Commit 02c2669

Browse files
committed
style(rubocop): Minitest/AssertPredicate
1 parent c0bce3c commit 02c2669

21 files changed

Lines changed: 132 additions & 132 deletions

test/html4/test_comments.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestComment < Nokogiri::TestCase
2626
if Nokogiri.libxml2_patches.include?("0008-htmlParseComment-handle-abruptly-closed-comments.patch")
2727
it "behaves as if the comment is closed correctly" do # COMPLIANT
2828
assert_equal 1, subject.children.length
29-
assert subject.children.first.comment?
29+
assert_predicate subject.children.first, :comment?
3030
assert_equal "", subject.children.first.content
3131
assert other_div
3232
end
@@ -43,7 +43,7 @@ class TestComment < Nokogiri::TestCase
4343
if Nokogiri.jruby?
4444
it "behaves as if the comment is closed correctly" do # COMPLIANT
4545
assert_equal 1, subject.children.length
46-
assert subject.children.first.comment?
46+
assert_predicate subject.children.first, :comment?
4747
assert_equal "", subject.children.first.content
4848
assert other_div
4949
end
@@ -57,7 +57,7 @@ class TestComment < Nokogiri::TestCase
5757
if Nokogiri.libxml2_patches.include?("0008-htmlParseComment-handle-abruptly-closed-comments.patch")
5858
it "behaves as if the comment is closed correctly" do # COMPLIANT
5959
assert_equal 1, subject.children.length
60-
assert subject.children.first.comment?
60+
assert_predicate subject.children.first, :comment?
6161
assert_equal "", subject.children.first.content
6262
assert other_div
6363
end
@@ -74,7 +74,7 @@ class TestComment < Nokogiri::TestCase
7474
if Nokogiri.jruby?
7575
it "behaves as if the comment is closed correctly" do # COMPLIANT
7676
assert_equal 1, subject.children.length
77-
assert subject.children.first.comment?
77+
assert_predicate subject.children.first, :comment?
7878
assert_equal "-", subject.children.first.content # curious, potentially non-compliant?
7979
assert other_div
8080
end
@@ -86,7 +86,7 @@ class TestComment < Nokogiri::TestCase
8686

8787
it "behaves as if the comment is closed correctly" do # COMPLIANT
8888
assert_equal 1, subject.children.length
89-
assert subject.children.first.comment?
89+
assert_predicate subject.children.first, :comment?
9090
assert_equal "", subject.children.first.content
9191
assert other_div
9292
end
@@ -115,7 +115,7 @@ class TestComment < Nokogiri::TestCase
115115
if Nokogiri.jruby?
116116
it "behaves as if the comment is closed immediately before the end of the input stream" do # COMPLIANT
117117
assert_equal 1, subject.children.length
118-
assert subject.children.first.comment?
118+
assert_predicate subject.children.first, :comment?
119119
assert_equal "start of unterminated comment", subject.children.first.content
120120
end
121121
end
@@ -136,11 +136,11 @@ class TestComment < Nokogiri::TestCase
136136
if Nokogiri::VersionInfo.instance.libxml2_using_packaged? || (Nokogiri::VersionInfo.instance.libxml2_using_system? && Nokogiri.uses_libxml?(">=2.9.11"))
137137
it "behaves as if the comment is normally closed" do # COMPLIANT
138138
assert_equal 3, subject.children.length
139-
assert subject.children[0].comment?
139+
assert_predicate subject.children[0], :comment?
140140
assert_equal "foo", subject.children[0].content
141141
assert inner_div
142142
assert_equal inner_div, subject.children[1]
143-
assert subject.children[2].comment?
143+
assert_predicate subject.children[2], :comment?
144144
assert_equal "bar", subject.children[2].content
145145
assert_equal 1, doc.errors.length
146146
assert_match(/Comment incorrectly closed/, doc.errors.first.to_s)
@@ -150,7 +150,7 @@ class TestComment < Nokogiri::TestCase
150150
if Nokogiri.jruby? || (Nokogiri::VersionInfo.instance.libxml2_using_system? && Nokogiri.uses_libxml?("<2.9.11"))
151151
it "behaves as if the comment encompasses the inner div" do # NON-COMPLIANT
152152
assert_equal 1, subject.children.length
153-
assert subject.children.first.comment?
153+
assert_predicate subject.children.first, :comment?
154154
refute inner_div
155155
assert_match(/id=do-i-exist/, subject.children.first.content)
156156
assert_equal 0, doc.errors.length
@@ -178,17 +178,17 @@ class TestComment < Nokogiri::TestCase
178178
assert_equal 2, body.children.length
179179
assert_equal body.children[0], subject
180180
assert_equal 1, subject.children.length
181-
assert subject.children[0].text?
181+
assert_predicate subject.children[0], :text?
182182
assert_equal "inner content", subject.children[0].content
183-
assert body.children[1].text?
183+
assert_predicate body.children[1], :text?
184184
assert_equal "-->hello", body.children[1].content
185185
end
186186
end
187187

188188
if Nokogiri.jruby?
189189
it "ignores up to the next '-->'" do # NON-COMPLIANT
190190
assert_equal 1, subject.children.length
191-
assert subject.children[0].text?
191+
assert_predicate subject.children[0], :text?
192192
assert_equal "hello", subject.children[0].content
193193
end
194194
end
@@ -208,11 +208,11 @@ class TestComment < Nokogiri::TestCase
208208

209209
it "ignores to the next '-->'" do # COMPLIANT
210210
assert_equal 3, subject.children.length
211-
assert subject.children[0].comment?
211+
assert_predicate subject.children[0], :comment?
212212
assert_equal " outer <!-- inner ", subject.children[0].content
213213
assert inner_div
214214
assert_equal inner_div, subject.children[1]
215-
assert subject.children[2].text?
215+
assert_predicate subject.children[2], :text?
216216
assert_equal "-->", subject.children[2].content
217217
end
218218
end

test/html4/test_document.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def test_document_takes_config_block
3838
options = cfg
3939
options.nonet.nowarning.dtdattr
4040
end
41-
assert(options.nonet?)
42-
assert(options.nowarning?)
43-
assert(options.dtdattr?)
41+
assert_predicate(options, :nonet?)
42+
assert_predicate(options, :nowarning?)
43+
assert_predicate(options, :dtdattr?)
4444
end
4545

4646
def test_parse_takes_config_block
@@ -49,9 +49,9 @@ def test_parse_takes_config_block
4949
options = cfg
5050
options.nonet.nowarning.dtdattr
5151
end
52-
assert(options.nonet?)
53-
assert(options.nowarning?)
54-
assert(options.dtdattr?)
52+
assert_predicate(options, :nonet?)
53+
assert_predicate(options, :nowarning?)
54+
assert_predicate(options, :dtdattr?)
5555
end
5656

5757
def test_subclass
@@ -339,7 +339,7 @@ def test_parse_empty_document
339339

340340
def test_HTML_function
341341
html = Nokogiri::HTML(File.read(HTML_FILE))
342-
assert(html.html?)
342+
assert_predicate(html, :html?)
343343
end
344344

345345
def test_parse_works_with_an_object_that_responds_to_read
@@ -535,9 +535,9 @@ def test_search_can_handle_xpath_and_css
535535
def test_dup_document
536536
assert(dup = html.dup)
537537
refute_equal(dup, html)
538-
assert(html.html?)
538+
assert_predicate(html, :html?)
539539
assert_instance_of(Nokogiri::HTML::Document, dup)
540-
assert(dup.html?, "duplicate should be html")
540+
assert_predicate(dup, :html?, "duplicate should be html")
541541
assert_equal(html.to_s, dup.to_s)
542542
end
543543

@@ -641,7 +641,7 @@ def test_parse_can_take_io
641641
File.open(HTML_FILE, "rb") do |f|
642642
html = Nokogiri::HTML(f)
643643
end
644-
assert(html.html?)
644+
assert_predicate(html, :html?)
645645
assert_equal(HTML_FILE, html.url)
646646
end
647647

@@ -668,8 +668,8 @@ def test_parse_can_take_pathnames
668668
end
669669

670670
def test_html?
671-
refute(html.xml?)
672-
assert(html.html?)
671+
refute_predicate(html, :xml?)
672+
assert_predicate(html, :html?)
673673
end
674674

675675
def test_serialize
@@ -780,7 +780,7 @@ def test_leaking_dtd_nodes_after_internal_subset_removal
780780
end
781781

782782
it "sets the test up correctly" do
783-
assert(html_strict.strict?)
783+
assert_predicate(html_strict, :strict?)
784784
end
785785

786786
describe "ill-formed < character" do

test/html4/test_document_fragment.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def test_dup_should_create_an_html_document_fragment
318318
let(:input) { "<div>foo</div" }
319319

320320
it "sets the test up correctly" do
321-
assert(html4_strict.strict?)
321+
assert_predicate(html4_strict, :strict?)
322322
end
323323

324324
describe "HTML4.fragment" do
@@ -343,7 +343,7 @@ def test_dup_should_create_an_html_document_fragment
343343
Nokogiri::HTML4.fragment(input) do |config|
344344
default_config = config
345345
end
346-
refute(default_config.strict?)
346+
refute_predicate(default_config, :strict?)
347347

348348
assert_raises(Nokogiri::SyntaxError) do
349349
Nokogiri::HTML4.fragment(input, &:norecover)
@@ -373,7 +373,7 @@ def test_dup_should_create_an_html_document_fragment
373373
Nokogiri::HTML4::DocumentFragment.parse(input) do |config|
374374
default_config = config
375375
end
376-
refute(default_config.strict?)
376+
refute_predicate(default_config, :strict?)
377377

378378
assert_raises(Nokogiri::SyntaxError) do
379379
Nokogiri::HTML4::DocumentFragment.parse(input, &:norecover)
@@ -404,7 +404,7 @@ def test_dup_should_create_an_html_document_fragment
404404
Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input) do |config|
405405
default_config = config
406406
end
407-
refute(default_config.strict?)
407+
refute_predicate(default_config, :strict?)
408408

409409
assert_raises(Nokogiri::SyntaxError) do
410410
Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input, &:norecover)
@@ -437,7 +437,7 @@ def test_dup_should_create_an_html_document_fragment
437437
Nokogiri::HTML4::DocumentFragment.new(document, input, context_node) do |config|
438438
default_config = config
439439
end
440-
refute(default_config.strict?)
440+
refute_predicate(default_config, :strict?)
441441

442442
assert_raises(Nokogiri::SyntaxError) do
443443
Nokogiri::HTML4::DocumentFragment.new(document, input, context_node, &:norecover)

test/html4/test_element_description.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ def test_name
1919
end
2020

2121
def test_implied_start_tag?
22-
refute(ElementDescription["a"].implied_start_tag?)
22+
refute_predicate(ElementDescription["a"], :implied_start_tag?)
2323
end
2424

2525
def test_implied_end_tag?
26-
refute(ElementDescription["a"].implied_end_tag?)
27-
assert(ElementDescription["p"].implied_end_tag?)
26+
refute_predicate(ElementDescription["a"], :implied_end_tag?)
27+
assert_predicate(ElementDescription["p"], :implied_end_tag?)
2828
end
2929

3030
def test_save_end_tag?
31-
refute(ElementDescription["a"].save_end_tag?)
32-
assert(ElementDescription["br"].save_end_tag?)
31+
refute_predicate(ElementDescription["a"], :save_end_tag?)
32+
assert_predicate(ElementDescription["br"], :save_end_tag?)
3333
end
3434

3535
def test_empty?
@@ -38,13 +38,13 @@ def test_empty?
3838
end
3939

4040
def test_deprecated?
41-
assert(ElementDescription["applet"].deprecated?)
42-
refute(ElementDescription["br"].deprecated?)
41+
assert_predicate(ElementDescription["applet"], :deprecated?)
42+
refute_predicate(ElementDescription["br"], :deprecated?)
4343
end
4444

4545
def test_inline?
46-
assert(ElementDescription["a"].inline?)
47-
refute(ElementDescription["div"].inline?)
46+
assert_predicate(ElementDescription["a"], :inline?)
47+
refute_predicate(ElementDescription["div"], :inline?)
4848
end
4949

5050
def test_block?

test/html5/test_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_fragment_from_node
156156
assert_equal(1, frag.children.length)
157157
nested_form = frag.at_xpath("form")
158158
assert_nil(nested_form)
159-
assert(frag.children[0].text?)
159+
assert_predicate(frag.children[0], :text?)
160160
end
161161

162162
def test_fragment_from_node_no_form
@@ -179,7 +179,7 @@ def test_empty_fragment
179179

180180
def test_html_eh
181181
doc = Nokogiri.HTML5("<html><body><div></div></body></html>")
182-
assert(doc.html?)
183-
refute(doc.xml?)
182+
assert_predicate(doc, :html?)
183+
refute_predicate(doc, :xml?)
184184
end
185185
end if Nokogiri.uses_gumbo?

test/html5/test_nokogumbo.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_element_cdata_textarea
1616

1717
def test_element_cdata_script
1818
doc = Nokogiri::HTML5.fragment(buffer)
19-
assert(doc.document.html?)
19+
assert_predicate(doc.document, :html?)
2020
assert_equal("<script> if (a < b) alert(1) </script>", doc.at("script").to_s)
2121
end
2222

@@ -318,7 +318,7 @@ def test_line_cdata
318318
html = "<!DOCTYPE html>\n<svg>\n<script><![CDATA[ ]]></script></svg>"
319319
doc = Nokogiri.HTML5(html)
320320
node = doc.at_xpath("/html/body/svg:svg/svg:script/text()")
321-
assert(node.cdata?)
321+
assert_predicate(node, :cdata?)
322322
assert_equal(3, node.line)
323323
end
324324

test/html5/test_null.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_cdata_section_state
107107

108108
def test_error_api_with_null
109109
frag = fragment("<p \u0000>")
110-
assert(frag.errors.any?)
110+
assert_predicate(frag.errors, :any?)
111111
assert_includes(frag.errors[0].to_s, "<p \u0000>")
112112
end
113113
end if Nokogiri.uses_gumbo?

test/test_css_cache.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def [](key)
2424
end
2525
end
2626

27-
assert(Nokogiri::CSS::Parser.cache_on?)
27+
assert_predicate(Nokogiri::CSS::Parser, :cache_on?)
2828
end
2929

3030
def teardown
@@ -105,9 +105,9 @@ def test_without_cache_resets_cache_value
105105
Nokogiri::CSS::Parser.set_cache(true)
106106

107107
Nokogiri::CSS::Parser.without_cache do
108-
refute(Nokogiri::CSS::Parser.cache_on?)
108+
refute_predicate(Nokogiri::CSS::Parser, :cache_on?)
109109
end
110-
assert(Nokogiri::CSS::Parser.cache_on?)
110+
assert_predicate(Nokogiri::CSS::Parser, :cache_on?)
111111
end
112112

113113
def test_without_cache_resets_cache_value_even_after_exception
@@ -118,7 +118,7 @@ def test_without_cache_resets_cache_value_even_after_exception
118118
raise RuntimeError
119119
end
120120
end
121-
assert(Nokogiri::CSS::Parser.cache_on?)
121+
assert_predicate(Nokogiri::CSS::Parser, :cache_on?)
122122
end
123123

124124
def test_cache_key_on_ns_prefix_and_visitor_config
@@ -165,6 +165,6 @@ def test_race_condition
165165

166166
threads.each(&:join)
167167

168-
assert(Nokogiri::CSS::Parser.cache_on?)
168+
assert_predicate(Nokogiri::CSS::Parser, :cache_on?)
169169
end
170170
end

test/test_nokogiri.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ def test_parse_with_io
1717

1818
def test_xml?
1919
doc = Nokogiri.parse(File.read(XML_FILE))
20-
assert(doc.xml?)
21-
refute(doc.html?)
20+
assert_predicate(doc, :xml?)
21+
refute_predicate(doc, :html?)
2222
end
2323

2424
def test_atom_is_xml?
2525
doc = Nokogiri.parse(File.read(XML_ATOM_FILE))
26-
assert(doc.xml?)
27-
refute(doc.html?)
26+
assert_predicate(doc, :xml?)
27+
refute_predicate(doc, :html?)
2828
end
2929

3030
def test_html?
3131
doc = Nokogiri.parse(File.read(HTML_FILE))
32-
refute(doc.xml?)
33-
assert(doc.html?)
32+
refute_predicate(doc, :xml?)
33+
assert_predicate(doc, :html?)
3434
end
3535

3636
def test_nokogiri_method_with_html

0 commit comments

Comments
 (0)