Skip to content

Commit a4971b9

Browse files
committed
refactor: Split tests with excessive assertions
Split test methods that exceeded the Minitest/MultipleAssertions limit into smaller, more focused tests.
1 parent 9e86627 commit a4971b9

File tree

5 files changed

+90
-46
lines changed

5 files changed

+90
-46
lines changed

.rubocop.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ AllCops:
2020
- 'test/profilers/**/*'
2121
TargetRubyVersion: 3.0
2222

23+
# Dear Rubocop, I don't want to use String#strip_heredoc
24+
Layout/HeredocIndentation:
25+
Enabled: false
26+
27+
Minitest/MultipleAssertions:
28+
Max: 10
29+
2330
# I often use @_variable to avoid clashing.
2431
Naming/MemoizedInstanceVariableName:
2532
Enabled: false
@@ -29,14 +36,10 @@ Style/ClassAndModuleChildren:
2936
- 'spec/**/*_spec.rb'
3037
- 'test/**/*_test.rb'
3138

32-
# Dear Rubocop, I don't want to use String#strip_heredoc
33-
Layout/HeredocIndentation:
34-
Enabled: false
35-
36-
Style/WordArray:
39+
Style/SymbolArray:
3740
Enabled: false
3841
MinSize: 3
3942

40-
Style/SymbolArray:
43+
Style/WordArray:
4144
Enabled: false
4245
MinSize: 3

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
8-
9-
# Offense count: 19
10-
Minitest/MultipleAssertions:
11-
Max: 12

test/acceptance_test.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@ class AcceptanceTest < Minitest::Test
1515
["foo.parliament.uk", "parliament.uk", ["foo", "parliament", "uk"]],
1616
].freeze
1717

18-
def test_valid
19-
VALID_CASES.each do |input, domain, results|
18+
def test_valid_parsing
19+
VALID_CASES.each do |input, _domain, results|
2020
parsed = PublicSuffix.parse(input)
2121
trd, sld, tld = results
2222

23-
assert_equal tld, parsed.tld, "Invalid tld for `#{name}`"
24-
assert_equal sld, parsed.sld, "Invalid sld for `#{name}`"
23+
assert_equal tld, parsed.tld, "Invalid tld for `#{input}`"
24+
assert_equal sld, parsed.sld, "Invalid sld for `#{input}`"
2525
if trd.nil?
26-
assert_nil parsed.trd, "Invalid trd for `#{name}`"
26+
assert_nil parsed.trd, "Invalid trd for `#{input}`"
2727
else
28-
assert_equal trd, parsed.trd, "Invalid trd for `#{name}`"
28+
assert_equal trd, parsed.trd, "Invalid trd for `#{input}`"
2929
end
30+
end
31+
end
3032

33+
def test_valid_domain
34+
VALID_CASES.each do |input, domain, _results|
3135
assert_equal domain, PublicSuffix.domain(input)
36+
end
37+
end
38+
39+
def test_valid_validation
40+
VALID_CASES.each do |input, _domain, _results|
3241
assert PublicSuffix.valid?(input)
3342
end
3443
end

test/unit/list_test.rb

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,47 @@ def test_clear
9696
end
9797

9898

99-
def test_find
100-
list = PublicSuffix::List.parse(<<LIST)
99+
def test_find_iana
100+
list = build_test_list
101+
102+
assert_equal PublicSuffix::Rule.factory("com"), list.find("example.com")
103+
assert_equal PublicSuffix::Rule.factory("com"), list.find("foo.example.com")
104+
end
105+
106+
def test_find_wildcard
107+
list = build_test_list
108+
109+
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.uk")
110+
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.co.uk")
111+
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("foo.example.co.uk")
112+
end
113+
114+
def test_find_exception
115+
list = build_test_list
116+
117+
assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("british-library.uk")
118+
assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("foo.british-library.uk")
119+
end
120+
121+
def test_find_default
122+
list = build_test_list
123+
124+
assert_equal PublicSuffix::Rule.factory("*"), list.find("test")
125+
assert_equal PublicSuffix::Rule.factory("*"), list.find("example.test")
126+
assert_equal PublicSuffix::Rule.factory("*"), list.find("foo.example.test")
127+
end
128+
129+
def test_find_private
130+
list = build_test_list
131+
132+
assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("blogspot.com")
133+
assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("foo.blogspot.com")
134+
end
135+
136+
private
137+
138+
def build_test_list
139+
PublicSuffix::List.parse(<<LIST)
101140
// This Source Code Form is subject to the terms of the Mozilla Public
102141
// License, v. 2.0. If a copy of the MPL was not distributed with this
103142
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
@@ -124,28 +163,6 @@ def test_find
124163
125164
// ===END PRIVATE DOMAINS===
126165
LIST
127-
128-
# match IANA
129-
assert_equal PublicSuffix::Rule.factory("com"), list.find("example.com")
130-
assert_equal PublicSuffix::Rule.factory("com"), list.find("foo.example.com")
131-
132-
# match wildcard
133-
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.uk")
134-
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.co.uk")
135-
assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("foo.example.co.uk")
136-
137-
# match exception
138-
assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("british-library.uk")
139-
assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("foo.british-library.uk")
140-
141-
# match default rule
142-
assert_equal PublicSuffix::Rule.factory("*"), list.find("test")
143-
assert_equal PublicSuffix::Rule.factory("*"), list.find("example.test")
144-
assert_equal PublicSuffix::Rule.factory("*"), list.find("foo.example.test")
145-
146-
# match private
147-
assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("blogspot.com")
148-
assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("foo.blogspot.com")
149166
end
150167

151168

test/unit/rule_test.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,58 @@ def test_equality_with_internals
7676
end
7777
# rubocop:enable Style/SingleLineMethods
7878

79-
def test_match
79+
def test_match_standard
8080
[
81-
# standard match
8281
[PublicSuffix::Rule.factory("uk"), "uk", true],
8382
[PublicSuffix::Rule.factory("uk"), "example.uk", true],
8483
[PublicSuffix::Rule.factory("uk"), "example.co.uk", true],
8584
[PublicSuffix::Rule.factory("co.uk"), "example.co.uk", true],
85+
].each do |rule, input, expected|
86+
assert_equal expected, rule.match?(input)
87+
end
88+
end
8689

90+
def test_match_wildcard_and_exception
91+
[
8792
# FIXME
8893
# [PublicSuffix::Rule.factory("*.com"), "com", false],
8994
[PublicSuffix::Rule.factory("*.com"), "example.com", true],
9095
[PublicSuffix::Rule.factory("*.com"), "foo.example.com", true],
9196
[PublicSuffix::Rule.factory("!example.com"), "com", false],
9297
[PublicSuffix::Rule.factory("!example.com"), "example.com", true],
9398
[PublicSuffix::Rule.factory("!example.com"), "foo.example.com", true],
99+
].each do |rule, input, expected|
100+
assert_equal expected, rule.match?(input)
101+
end
102+
end
94103

95-
# TLD mismatch
104+
def test_match_tld_mismatch
105+
[
96106
[PublicSuffix::Rule.factory("gk"), "example.uk", false],
97107
[PublicSuffix::Rule.factory("gk"), "example.co.uk", false],
98108
[PublicSuffix::Rule.factory("co.uk"), "uk", false],
109+
].each do |rule, input, expected|
110+
assert_equal expected, rule.match?(input)
111+
end
112+
end
99113

100-
# general mismatch
114+
def test_match_general_mismatch
115+
[
101116
[PublicSuffix::Rule.factory("uk.co"), "example.co.uk", false],
102117
[PublicSuffix::Rule.factory("go.uk"), "example.co.uk", false],
103118
[PublicSuffix::Rule.factory("co.uk"), "uk", false],
119+
].each do |rule, input, expected|
120+
assert_equal expected, rule.match?(input)
121+
end
122+
end
104123

105-
# partial matches/mismatches
124+
def test_match_partial
125+
[
106126
[PublicSuffix::Rule.factory("co"), "example.co.uk", false],
107127
[PublicSuffix::Rule.factory("example"), "example.uk", false],
108128
[PublicSuffix::Rule.factory("le.it"), "example.it", false],
109129
[PublicSuffix::Rule.factory("le.it"), "le.it", true],
110130
[PublicSuffix::Rule.factory("le.it"), "foo.le.it", true],
111-
112131
].each do |rule, input, expected|
113132
assert_equal expected, rule.match?(input)
114133
end

0 commit comments

Comments
 (0)