rubocop-minitest 0.10.0 → 0.11.1
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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +18 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +5 -1
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +8 -7
- data/CHANGELOG.md +90 -49
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +18 -2
- data/Rakefile +1 -1
- data/bin/console +2 -0
- data/config/default.yml +10 -4
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +13 -1
- data/docs/modules/ROOT/pages/cops_minitest.adoc +47 -8
- data/docs/modules/ROOT/pages/index.adoc +1 -1
- data/legacy-docs/cops_minitest.md +16 -16
- data/legacy-docs/index.md +1 -1
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +9 -8
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +2 -0
- data/lib/rubocop/cop/minitest/assert_nil.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_truthy.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +41 -0
- data/lib/rubocop/cop/minitest/global_expectations.rb +2 -0
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_equal.rb +2 -1
- data/lib/rubocop/cop/minitest/refute_false.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +2 -0
- data/lib/rubocop/cop/minitest/refute_nil.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +1 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +10 -1
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +2 -1
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +14 -1
- data/lib/rubocop/minitest/version.rb +8 -1
- data/mkdocs.yml +2 -2
- data/relnotes/v0.1.0.md +1 -1
- data/relnotes/v0.10.0.md +12 -12
- data/relnotes/v0.10.1.md +5 -0
- data/relnotes/v0.10.2.md +5 -0
- data/relnotes/v0.10.3.md +5 -0
- data/relnotes/v0.11.0.md +16 -0
- data/relnotes/v0.11.1.md +5 -0
- data/relnotes/v0.2.0.md +4 -4
- data/relnotes/v0.2.1.md +1 -1
- data/relnotes/v0.3.0.md +6 -6
- data/relnotes/v0.4.0.md +5 -5
- data/relnotes/v0.4.1.md +1 -1
- data/relnotes/v0.5.0.md +1 -1
- data/relnotes/v0.5.1.md +1 -1
- data/relnotes/v0.6.0.md +1 -1
- data/relnotes/v0.6.1.md +2 -2
- data/relnotes/v0.6.2.md +1 -1
- data/relnotes/v0.7.0.md +5 -5
- data/relnotes/v0.8.0.md +4 -4
- data/relnotes/v0.8.1.md +1 -1
- data/relnotes/v0.9.0.md +3 -3
- data/rubocop-minitest.gemspec +6 -6
- data/tasks/cops_documentation.rake +15 -295
- data/tasks/cut_release.rake +1 -1
- metadata +26 -14
data/docs/antora.yml
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
+
= Cops
|
2
|
+
|
3
|
+
In RuboCop lingo the various checks performed on the code are called cops.
|
4
|
+
Each cop is responsible for detecting one particular offense.
|
5
|
+
RuboCop Minitest has only one Minitest department.
|
6
|
+
|
7
|
+
== Minitest
|
8
|
+
|
9
|
+
Minitest cops check for Minitest best practices and coding conventions. Many of the them are
|
10
|
+
based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
|
11
|
+
|
1
12
|
// START_COP_LIST
|
2
13
|
|
3
|
-
|
14
|
+
=== Department xref:cops_minitest.adoc[Minitest]
|
4
15
|
|
5
16
|
* xref:cops_minitest.adoc#minitestassertempty[Minitest/AssertEmpty]
|
6
17
|
* xref:cops_minitest.adoc#minitestassertemptyliteral[Minitest/AssertEmptyLiteral]
|
@@ -16,6 +27,7 @@
|
|
16
27
|
* xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo]
|
17
28
|
* xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent]
|
18
29
|
* xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
|
30
|
+
* xref:cops_minitest.adoc#minitestassertwithexpectedargument[Minitest/AssertWithExpectedArgument]
|
19
31
|
* xref:cops_minitest.adoc#minitestassertioninlifecyclehook[Minitest/AssertionInLifecycleHook]
|
20
32
|
* xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
|
21
33
|
* xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
|
@@ -41,19 +41,19 @@ assert_empty(object, 'message')
|
|
41
41
|
| Yes
|
42
42
|
| Yes (Unsafe)
|
43
43
|
| 0.5
|
44
|
-
| 0.
|
44
|
+
| 0.11
|
45
45
|
|===
|
46
46
|
|
47
47
|
This cop enforces the test to use `assert_empty`
|
48
|
-
instead of using `
|
48
|
+
instead of using `assert_equal([], object)`.
|
49
49
|
|
50
50
|
=== Examples
|
51
51
|
|
52
52
|
[source,ruby]
|
53
53
|
----
|
54
54
|
# bad
|
55
|
-
|
56
|
-
|
55
|
+
assert_equal([], object)
|
56
|
+
assert_equal({}, object)
|
57
57
|
|
58
58
|
# good
|
59
59
|
assert_empty(object)
|
@@ -215,7 +215,7 @@ assert_kind_of(Class, object, 'message')
|
|
215
215
|
|
216
216
|
=== References
|
217
217
|
|
218
|
-
* https://github.com/rubocop
|
218
|
+
* https://github.com/rubocop/minitest-style-guide#assert-kind-of
|
219
219
|
|
220
220
|
== Minitest/AssertMatch
|
221
221
|
|
@@ -407,7 +407,7 @@ assert_silent { puts object.do_something }
|
|
407
407
|
|
408
408
|
=== References
|
409
409
|
|
410
|
-
* https://github.com/rubocop
|
410
|
+
* https://github.com/rubocop/minitest-style-guide#assert-silent
|
411
411
|
|
412
412
|
== Minitest/AssertTruthy
|
413
413
|
|
@@ -441,6 +441,38 @@ assert(actual, 'message')
|
|
441
441
|
|
442
442
|
* https://minitest.rubystyle.guide#assert-truthy
|
443
443
|
|
444
|
+
== Minitest/AssertWithExpectedArgument
|
445
|
+
|
446
|
+
|===
|
447
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
448
|
+
|
449
|
+
| Pending
|
450
|
+
| No
|
451
|
+
| No
|
452
|
+
| 0.11
|
453
|
+
| -
|
454
|
+
|===
|
455
|
+
|
456
|
+
This cop tries to detect when a user accidentally used
|
457
|
+
`assert` when they meant to use `assert_equal`.
|
458
|
+
|
459
|
+
It is marked as unsafe because it is not possible to determine
|
460
|
+
whether the second argument of `assert` is a message or not.
|
461
|
+
|
462
|
+
=== Examples
|
463
|
+
|
464
|
+
[source,ruby]
|
465
|
+
----
|
466
|
+
# bad
|
467
|
+
assert(3, my_list.length)
|
468
|
+
assert(expected, actual)
|
469
|
+
|
470
|
+
# good
|
471
|
+
assert_equal(3, my_list.length)
|
472
|
+
assert_equal(expected, actual)
|
473
|
+
assert(foo, 'message')
|
474
|
+
----
|
475
|
+
|
444
476
|
== Minitest/AssertionInLifecycleHook
|
445
477
|
|
446
478
|
|===
|
@@ -638,7 +670,7 @@ refute_empty(object, 'message')
|
|
638
670
|
|===
|
639
671
|
|
640
672
|
This cop enforces the use of `refute_equal(expected, object)`
|
641
|
-
over `
|
673
|
+
over `assert(expected != actual)` or `assert(! expected == actual)`.
|
642
674
|
|
643
675
|
=== Examples
|
644
676
|
|
@@ -817,7 +849,7 @@ refute_kind_of(Class, object, 'message')
|
|
817
849
|
|
818
850
|
=== References
|
819
851
|
|
820
|
-
* https://github.com/rubocop
|
852
|
+
* https://github.com/rubocop/minitest-style-guide#refute-kind-of
|
821
853
|
|
822
854
|
== Minitest/RefuteMatch
|
823
855
|
|
@@ -962,6 +994,7 @@ refute_respond_to(self, :do_something)
|
|
962
994
|
|===
|
963
995
|
|
964
996
|
This cop enforces that test method names start with `test_` prefix.
|
997
|
+
It aims to prevent tests that aren't executed by forgetting to start test method name with `test_`.
|
965
998
|
|
966
999
|
=== Examples
|
967
1000
|
|
@@ -980,6 +1013,12 @@ class FooTest < Minitest::Test
|
|
980
1013
|
assert_equal 42, do_something
|
981
1014
|
end
|
982
1015
|
end
|
1016
|
+
|
1017
|
+
# good
|
1018
|
+
class FooTest < Minitest::Test
|
1019
|
+
def helper_method(argument)
|
1020
|
+
end
|
1021
|
+
end
|
983
1022
|
----
|
984
1023
|
|
985
1024
|
== Minitest/UnspecifiedException
|
@@ -1,5 +1,5 @@
|
|
1
1
|
= RuboCop Minitest
|
2
2
|
|
3
|
-
A https://github.com/rubocop
|
3
|
+
A https://github.com/rubocop/rubocop[RuboCop] extension focused on enforcing Minitest best practices and coding conventions.
|
4
4
|
|
5
5
|
It's based on the community-driven https://minitest.rubystyle.guide[Minitest style guide].
|
@@ -23,7 +23,7 @@ assert_empty(object, 'message')
|
|
23
23
|
|
24
24
|
### References
|
25
25
|
|
26
|
-
* [https://github.com/rubocop
|
26
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-empty](https://github.com/rubocop/minitest-style-guide#assert-empty)
|
27
27
|
|
28
28
|
## Minitest/AssertEmptyLiteral
|
29
29
|
|
@@ -66,7 +66,7 @@ assert_equal("rubocop-minitest", actual)
|
|
66
66
|
|
67
67
|
### References
|
68
68
|
|
69
|
-
* [https://github.com/rubocop
|
69
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-equal-arguments-order](https://github.com/rubocop/minitest-style-guide#assert-equal-arguments-order)
|
70
70
|
|
71
71
|
## Minitest/AssertIncludes
|
72
72
|
|
@@ -91,7 +91,7 @@ assert_includes(collection, object, 'message')
|
|
91
91
|
|
92
92
|
### References
|
93
93
|
|
94
|
-
* [https://github.com/rubocop
|
94
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-includes](https://github.com/rubocop/minitest-style-guide#assert-includes)
|
95
95
|
|
96
96
|
## Minitest/AssertInstanceOf
|
97
97
|
|
@@ -116,7 +116,7 @@ assert_instance_of(Class, object, 'message')
|
|
116
116
|
|
117
117
|
### References
|
118
118
|
|
119
|
-
* [https://github.com/rubocop
|
119
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-instance-of](https://github.com/rubocop/minitest-style-guide#assert-instance-of)
|
120
120
|
|
121
121
|
## Minitest/AssertMatch
|
122
122
|
|
@@ -141,7 +141,7 @@ assert_match(matcher, string, 'message')
|
|
141
141
|
|
142
142
|
### References
|
143
143
|
|
144
|
-
* [https://github.com/rubocop
|
144
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-match](https://github.com/rubocop/minitest-style-guide#assert-match)
|
145
145
|
|
146
146
|
## Minitest/AssertNil
|
147
147
|
|
@@ -166,7 +166,7 @@ assert_nil(actual, 'message')
|
|
166
166
|
|
167
167
|
### References
|
168
168
|
|
169
|
-
* [https://github.com/rubocop
|
169
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-nil](https://github.com/rubocop/minitest-style-guide#assert-nil)
|
170
170
|
|
171
171
|
## Minitest/AssertRespondTo
|
172
172
|
|
@@ -193,7 +193,7 @@ assert_respond_to(self, :do_something)
|
|
193
193
|
|
194
194
|
### References
|
195
195
|
|
196
|
-
* [https://github.com/rubocop
|
196
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-responds-to-method](https://github.com/rubocop/minitest-style-guide#assert-responds-to-method)
|
197
197
|
|
198
198
|
## Minitest/AssertTruthy
|
199
199
|
|
@@ -218,7 +218,7 @@ assert(actual, 'message')
|
|
218
218
|
|
219
219
|
### References
|
220
220
|
|
221
|
-
* [https://github.com/rubocop
|
221
|
+
* [https://github.com/rubocop/minitest-style-guide#assert-truthy](https://github.com/rubocop/minitest-style-guide#assert-truthy)
|
222
222
|
|
223
223
|
## Minitest/GlobalExpectations
|
224
224
|
|
@@ -266,7 +266,7 @@ refute_empty(object, 'message')
|
|
266
266
|
|
267
267
|
### References
|
268
268
|
|
269
|
-
* [https://github.com/rubocop
|
269
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-empty](https://github.com/rubocop/minitest-style-guide#refute-empty)
|
270
270
|
|
271
271
|
## Minitest/RefuteEqual
|
272
272
|
|
@@ -290,7 +290,7 @@ refute_equal("rubocop-minitest", actual)
|
|
290
290
|
|
291
291
|
### References
|
292
292
|
|
293
|
-
* [https://github.com/rubocop
|
293
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-equal](https://github.com/rubocop/minitest-style-guide#refute-equal)
|
294
294
|
|
295
295
|
## Minitest/RefuteFalse
|
296
296
|
|
@@ -318,7 +318,7 @@ refute(actual, 'message')
|
|
318
318
|
|
319
319
|
### References
|
320
320
|
|
321
|
-
* [https://github.com/rubocop
|
321
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-false](https://github.com/rubocop/minitest-style-guide#refute-false)
|
322
322
|
|
323
323
|
## Minitest/RefuteIncludes
|
324
324
|
|
@@ -343,7 +343,7 @@ refute_includes(collection, object, 'message')
|
|
343
343
|
|
344
344
|
### References
|
345
345
|
|
346
|
-
* [https://github.com/rubocop
|
346
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-includes](https://github.com/rubocop/minitest-style-guide#refute-includes)
|
347
347
|
|
348
348
|
## Minitest/RefuteInstanceOf
|
349
349
|
|
@@ -368,7 +368,7 @@ refute_instance_of(Class, object, 'message')
|
|
368
368
|
|
369
369
|
### References
|
370
370
|
|
371
|
-
* [https://github.com/rubocop
|
371
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-instance-of](https://github.com/rubocop/minitest-style-guide#refute-instance-of)
|
372
372
|
|
373
373
|
## Minitest/RefuteMatch
|
374
374
|
|
@@ -393,7 +393,7 @@ refute_match(matcher, string, 'message')
|
|
393
393
|
|
394
394
|
### References
|
395
395
|
|
396
|
-
* [https://github.com/rubocop
|
396
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-match](https://github.com/rubocop/minitest-style-guide#refute-match)
|
397
397
|
|
398
398
|
## Minitest/RefuteNil
|
399
399
|
|
@@ -418,7 +418,7 @@ refute_nil(actual, 'message')
|
|
418
418
|
|
419
419
|
### References
|
420
420
|
|
421
|
-
* [https://github.com/rubocop
|
421
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-nil](https://github.com/rubocop/minitest-style-guide#refute-nil)
|
422
422
|
|
423
423
|
## Minitest/RefuteRespondTo
|
424
424
|
|
@@ -445,4 +445,4 @@ refute_respond_to(self, :do_something)
|
|
445
445
|
|
446
446
|
### References
|
447
447
|
|
448
|
-
* [https://github.com/rubocop
|
448
|
+
* [https://github.com/rubocop/minitest-style-guide#refute-respond-to](https://github.com/rubocop/minitest-style-guide#refute-respond-to)
|
data/legacy-docs/index.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
A [RuboCop](https://github.com/rubocop
|
1
|
+
A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Minitest best practices and coding conventions.
|
@@ -4,12 +4,12 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
6
|
# This cop enforces the test to use `assert_empty`
|
7
|
-
# instead of using `
|
7
|
+
# instead of using `assert_equal([], object)`.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# assert_equal([], object)
|
12
|
+
# assert_equal({}, object)
|
13
13
|
#
|
14
14
|
# # good
|
15
15
|
# assert_empty(object)
|
@@ -18,14 +18,15 @@ module RuboCop
|
|
18
18
|
include ArgumentRangeHelper
|
19
19
|
|
20
20
|
MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
|
21
|
-
'`
|
21
|
+
'`assert_equal(%<literal>s, %<arguments>s)`.'
|
22
|
+
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
22
23
|
|
23
|
-
def_node_matcher :
|
24
|
-
(send nil? :
|
24
|
+
def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN
|
25
|
+
(send nil? :assert_equal ${hash array} $...)
|
25
26
|
PATTERN
|
26
27
|
|
27
28
|
def on_send(node)
|
28
|
-
|
29
|
+
assert_equal_with_empty_literal(node) do |literal, matchers|
|
29
30
|
return unless literal.values.empty?
|
30
31
|
|
31
32
|
args = matchers.map(&:source).join(', ')
|
@@ -36,7 +37,7 @@ module RuboCop
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def autocorrect(node)
|
39
|
-
|
40
|
+
assert_equal_with_empty_literal(node) do |_literal, matchers|
|
40
41
|
object = matchers.first
|
41
42
|
|
42
43
|
lambda do |corrector|
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
|
21
21
|
MSG = 'Prefer using `assert_nil(%<arguments>s)` over ' \
|
22
22
|
'`assert_equal(nil, %<arguments>s)`.'
|
23
|
+
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
23
24
|
|
24
25
|
def_node_matcher :assert_equal_with_nil, <<~PATTERN
|
25
26
|
(send nil? :assert_equal nil $_ $...)
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
|
21
21
|
MSG = 'Prefer using `assert(%<arguments>s)` over ' \
|
22
22
|
'`assert_equal(true, %<arguments>s)`.'
|
23
|
+
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
23
24
|
|
24
25
|
def_node_matcher :assert_equal_with_truthy, <<~PATTERN
|
25
26
|
(send nil? :assert_equal true $_ $...)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop tries to detect when a user accidentally used
|
7
|
+
# `assert` when they meant to use `assert_equal`.
|
8
|
+
#
|
9
|
+
# It is marked as unsafe because it is not possible to determine
|
10
|
+
# whether the second argument of `assert` is a message or not.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# assert(3, my_list.length)
|
15
|
+
# assert(expected, actual)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# assert_equal(3, my_list.length)
|
19
|
+
# assert_equal(expected, actual)
|
20
|
+
# assert(foo, 'message')
|
21
|
+
#
|
22
|
+
class AssertWithExpectedArgument < Cop
|
23
|
+
MSG = 'Did you mean to use `assert_equal(%<arguments>s)`?'
|
24
|
+
RESTRICT_ON_SEND = %i[assert].freeze
|
25
|
+
|
26
|
+
def_node_matcher :assert_with_two_arguments?, <<~PATTERN
|
27
|
+
(send nil? :assert $_ $_)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
assert_with_two_arguments?(node) do |_expected, message|
|
32
|
+
return if message.str_type? || message.dstr_type?
|
33
|
+
|
34
|
+
arguments = node.arguments.map(&:source).join(', ')
|
35
|
+
add_offense(node, message: format(MSG, arguments: arguments))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
6
|
# This cop enforces the use of `refute_equal(expected, object)`
|
7
|
-
# over `
|
7
|
+
# over `assert(expected != actual)` or `assert(! expected == actual)`.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
@@ -19,6 +19,7 @@ module RuboCop
|
|
19
19
|
|
20
20
|
MSG = 'Prefer using `refute_equal(%<preferred>s)` over ' \
|
21
21
|
'`assert(%<over>s)`.'
|
22
|
+
RESTRICT_ON_SEND = %i[assert].freeze
|
22
23
|
|
23
24
|
def_node_matcher :assert_not_equal, <<~PATTERN
|
24
25
|
(send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... )
|