rubocop-minitest 0.10.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +18 -3
- data/.github/ISSUE_TEMPLATE/bug_report.md +5 -1
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +8 -7
- data/CHANGELOG.md +95 -50
- 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 +15 -4
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +14 -1
- data/docs/modules/ROOT/pages/cops_minitest.adoc +79 -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.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +12 -16
- data/lib/rubocop/cop/minitest/assert_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +4 -1
- data/lib/rubocop/cop/minitest/assert_includes.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_instance_of.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_kind_of.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_match.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_nil.rb +5 -11
- data/lib/rubocop/cop/minitest/assert_output.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +6 -12
- data/lib/rubocop/cop/minitest/assert_respond_to.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_silent.rb +8 -6
- data/lib/rubocop/cop/minitest/assert_truthy.rb +5 -11
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +41 -0
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +1 -1
- data/lib/rubocop/cop/minitest/global_expectations.rb +6 -7
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +15 -14
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +2 -2
- data/lib/rubocop/cop/minitest/no_assertions.rb +48 -0
- data/lib/rubocop/cop/minitest/refute_empty.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_equal.rb +7 -8
- data/lib/rubocop/cop/minitest/refute_false.rb +15 -22
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +4 -1
- data/lib/rubocop/cop/minitest/refute_includes.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_instance_of.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_kind_of.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_match.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_nil.rb +4 -8
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +6 -12
- data/lib/rubocop/cop/minitest/refute_respond_to.rb +1 -1
- data/lib/rubocop/cop/minitest/test_method_name.rb +18 -8
- data/lib/rubocop/cop/minitest/unspecified_exception.rb +1 -1
- data/lib/rubocop/cop/minitest_cops.rb +2 -0
- data/lib/rubocop/cop/mixin/in_delta_mixin.rb +5 -15
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +13 -13
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +27 -3
- 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 +1 -1
- 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.12.0.md +10 -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 +7 -7
- data/tasks/cops_documentation.rake +24 -304
- metadata +28 -15
data/bin/console
CHANGED
data/config/default.yml
CHANGED
@@ -15,7 +15,7 @@ Minitest/AssertEmptyLiteral:
|
|
15
15
|
Enabled: true
|
16
16
|
SafeAutoCorrect: false
|
17
17
|
VersionAdded: '0.5'
|
18
|
-
VersionChanged: '0.
|
18
|
+
VersionChanged: '0.11'
|
19
19
|
|
20
20
|
Minitest/AssertEqual:
|
21
21
|
Description: 'This cop enforces the test to use `assert_equal` instead of using `assert(expected == actual)`.'
|
@@ -54,7 +54,7 @@ Minitest/AssertInstanceOf:
|
|
54
54
|
|
55
55
|
Minitest/AssertKindOf:
|
56
56
|
Description: 'This cop enforces the test to use `assert_kind_of(Class, object)` over `assert(object.kind_of?(Class))`'
|
57
|
-
StyleGuide: 'https://github.com/rubocop
|
57
|
+
StyleGuide: 'https://github.com/rubocop/minitest-style-guide#assert-kind-of'
|
58
58
|
Enabled: 'pending'
|
59
59
|
VersionAdded: '0.10'
|
60
60
|
|
@@ -84,7 +84,7 @@ Minitest/AssertRespondTo:
|
|
84
84
|
|
85
85
|
Minitest/AssertSilent:
|
86
86
|
Description: "This cop enforces the test to use `assert_silent { ... }` instead of using `assert_output('', '') { ... }`."
|
87
|
-
StyleGuide: 'https://github.com/rubocop
|
87
|
+
StyleGuide: 'https://github.com/rubocop/minitest-style-guide#assert-silent'
|
88
88
|
Enabled: 'pending'
|
89
89
|
VersionAdded: '0.10'
|
90
90
|
|
@@ -94,6 +94,12 @@ Minitest/AssertTruthy:
|
|
94
94
|
Enabled: true
|
95
95
|
VersionAdded: '0.2'
|
96
96
|
|
97
|
+
Minitest/AssertWithExpectedArgument:
|
98
|
+
Description: 'This cop tries to detect when a user accidentally used `assert` when they meant to use `assert_equal`.'
|
99
|
+
Enabled: pending
|
100
|
+
Safe: false
|
101
|
+
VersionAdded: '0.11'
|
102
|
+
|
97
103
|
Minitest/GlobalExpectations:
|
98
104
|
Description: 'This cop checks for deprecated global expectations.'
|
99
105
|
StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
|
@@ -112,6 +118,11 @@ Minitest/MultipleAssertions:
|
|
112
118
|
VersionAdded: '0.10'
|
113
119
|
Max: 3
|
114
120
|
|
121
|
+
Minitest/NoAssertions:
|
122
|
+
Description: 'This cop checks for at least one assertion (or flunk) in tests.'
|
123
|
+
Enabled: false
|
124
|
+
VersionAdded: '0.12'
|
125
|
+
|
115
126
|
Minitest/RefuteEmpty:
|
116
127
|
Description: 'This cop enforces to use `refute_empty` instead of using `refute(object.empty?)`.'
|
117
128
|
StyleGuide: 'https://minitest.rubystyle.guide#refute-empty'
|
@@ -156,7 +167,7 @@ Minitest/RefuteInstanceOf:
|
|
156
167
|
|
157
168
|
Minitest/RefuteKindOf:
|
158
169
|
Description: 'This cop enforces the test to use `refute_kind_of(Class, object)` over `refute(object.kind_of?(Class))`.'
|
159
|
-
StyleGuide: 'https://github.com/rubocop
|
170
|
+
StyleGuide: 'https://github.com/rubocop/minitest-style-guide#refute-kind-of'
|
160
171
|
Enabled: 'pending'
|
161
172
|
VersionAdded: '0.10'
|
162
173
|
|
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,10 +27,12 @@
|
|
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]
|
22
34
|
* xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
|
35
|
+
* xref:cops_minitest.adoc#minitestnoassertions[Minitest/NoAssertions]
|
23
36
|
* xref:cops_minitest.adoc#minitestrefuteempty[Minitest/RefuteEmpty]
|
24
37
|
* xref:cops_minitest.adoc#minitestrefuteequal[Minitest/RefuteEqual]
|
25
38
|
* xref:cops_minitest.adoc#minitestrefutefalse[Minitest/RefuteFalse]
|
@@ -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
|
|===
|
@@ -593,6 +625,38 @@ end
|
|
593
625
|
| Integer
|
594
626
|
|===
|
595
627
|
|
628
|
+
== Minitest/NoAssertions
|
629
|
+
|
630
|
+
|===
|
631
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
632
|
+
|
633
|
+
| Disabled
|
634
|
+
| Yes
|
635
|
+
| No
|
636
|
+
| 0.12
|
637
|
+
| -
|
638
|
+
|===
|
639
|
+
|
640
|
+
This cop checks if test cases contain any assertion calls.
|
641
|
+
|
642
|
+
=== Examples
|
643
|
+
|
644
|
+
[source,ruby]
|
645
|
+
----
|
646
|
+
# bad
|
647
|
+
class FooTest < Minitest::Test
|
648
|
+
def test_the_truth
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
# good
|
653
|
+
class FooTest < Minitest::Test
|
654
|
+
def test_the_truth
|
655
|
+
assert true
|
656
|
+
end
|
657
|
+
end
|
658
|
+
----
|
659
|
+
|
596
660
|
== Minitest/RefuteEmpty
|
597
661
|
|
598
662
|
|===
|
@@ -638,7 +702,7 @@ refute_empty(object, 'message')
|
|
638
702
|
|===
|
639
703
|
|
640
704
|
This cop enforces the use of `refute_equal(expected, object)`
|
641
|
-
over `
|
705
|
+
over `assert(expected != actual)` or `assert(! expected == actual)`.
|
642
706
|
|
643
707
|
=== Examples
|
644
708
|
|
@@ -817,7 +881,7 @@ refute_kind_of(Class, object, 'message')
|
|
817
881
|
|
818
882
|
=== References
|
819
883
|
|
820
|
-
* https://github.com/rubocop
|
884
|
+
* https://github.com/rubocop/minitest-style-guide#refute-kind-of
|
821
885
|
|
822
886
|
== Minitest/RefuteMatch
|
823
887
|
|
@@ -962,6 +1026,7 @@ refute_respond_to(self, :do_something)
|
|
962
1026
|
|===
|
963
1027
|
|
964
1028
|
This cop enforces that test method names start with `test_` prefix.
|
1029
|
+
It aims to prevent tests that aren't executed by forgetting to start test method name with `test_`.
|
965
1030
|
|
966
1031
|
=== Examples
|
967
1032
|
|
@@ -980,6 +1045,12 @@ class FooTest < Minitest::Test
|
|
980
1045
|
assert_equal 42, do_something
|
981
1046
|
end
|
982
1047
|
end
|
1048
|
+
|
1049
|
+
# good
|
1050
|
+
class FooTest < Minitest::Test
|
1051
|
+
def helper_method(argument)
|
1052
|
+
end
|
1053
|
+
end
|
983
1054
|
----
|
984
1055
|
|
985
1056
|
== 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,42 +4,38 @@ 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)
|
16
16
|
#
|
17
|
-
class AssertEmptyLiteral <
|
17
|
+
class AssertEmptyLiteral < Base
|
18
18
|
include ArgumentRangeHelper
|
19
|
+
extend AutoCorrector
|
19
20
|
|
20
21
|
MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
|
21
|
-
'`
|
22
|
+
'`assert_equal(%<literal>s, %<arguments>s)`.'
|
23
|
+
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
22
24
|
|
23
|
-
def_node_matcher :
|
24
|
-
(send nil? :
|
25
|
+
def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN
|
26
|
+
(send nil? :assert_equal ${hash array} $...)
|
25
27
|
PATTERN
|
26
28
|
|
27
29
|
def on_send(node)
|
28
|
-
|
30
|
+
assert_equal_with_empty_literal(node) do |literal, matchers|
|
29
31
|
return unless literal.values.empty?
|
30
32
|
|
31
33
|
args = matchers.map(&:source).join(', ')
|
32
34
|
|
33
35
|
message = format(MSG, literal: literal.source, arguments: args)
|
34
|
-
add_offense(node, message: message)
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def autocorrect(node)
|
39
|
-
assert_with_empty_literal(node) do |_literal, matchers|
|
40
|
-
object = matchers.first
|
36
|
+
add_offense(node, message: message) do |corrector|
|
37
|
+
object = matchers.first
|
41
38
|
|
42
|
-
lambda do |corrector|
|
43
39
|
corrector.replace(node.loc.selector, 'assert_empty')
|
44
40
|
corrector.replace(first_and_second_arguments_range(node), object.source)
|
45
41
|
end
|