rubocop-minitest 0.11.0 → 0.14.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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -3
- data/.rubocop.yml +14 -1
- data/CHANGELOG.md +34 -0
- data/Gemfile +1 -1
- data/config/default.yml +11 -0
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +2 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +68 -1
- data/lib/rubocop/cop/minitest/assert_empty.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +4 -9
- data/lib/rubocop/cop/minitest/assert_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +2 -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 +4 -11
- data/lib/rubocop/cop/minitest/assert_output.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +5 -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 +4 -11
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +4 -1
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +1 -1
- data/lib/rubocop/cop/minitest/global_expectations.rb +4 -7
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +14 -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 +5 -7
- data/lib/rubocop/cop/minitest/refute_false.rb +16 -26
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +2 -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 +3 -8
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +5 -12
- data/lib/rubocop/cop/minitest/refute_respond_to.rb +1 -1
- data/lib/rubocop/cop/minitest/test_method_name.rb +8 -7
- data/lib/rubocop/cop/minitest/unreachable_assertion.rb +42 -0
- 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 +11 -12
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +14 -4
- data/lib/rubocop/minitest/version.rb +1 -1
- data/relnotes/v0.11.1.md +5 -0
- data/relnotes/v0.12.0.md +10 -0
- data/relnotes/v0.12.1.md +5 -0
- data/relnotes/v0.13.0.md +5 -0
- data/relnotes/v0.14.0.md +5 -0
- data/rubocop-minitest.gemspec +1 -1
- data/tasks/cops_documentation.rake +11 -14
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcdc752936f6002cc925a5ca82039770b2977685a53f182250b0cc75fffbb412
|
4
|
+
data.tar.gz: a634c0d0fa393ef7f00b07ebb8c17063df18c8e4d92643eb361699c1fa327097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1879892d3bb7d99c4e2e1c483f1c9f93b990f55fecc71f5ae37b0193bfde0ae7167588d21fbf3a62abdfa26f4e88efc2655d0ddc4e0f078f23fe5f05843e95ca
|
7
|
+
data.tar.gz: c411392994e053920757c682c793defae132d9fd4e556c131f6c4a74fef3d93dca05fab0f3bd91a3081e038a943dd41a00b88626966b0c74928e97afa0cec65f
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -9,7 +9,7 @@ require:
|
|
9
9
|
|
10
10
|
AllCops:
|
11
11
|
NewCops: enable
|
12
|
-
TargetRubyVersion: 2.
|
12
|
+
TargetRubyVersion: 2.5
|
13
13
|
SuggestExtensions: false
|
14
14
|
|
15
15
|
InternalAffairs/NodeMatcherDirective:
|
@@ -23,6 +23,19 @@ Naming/PredicateName:
|
|
23
23
|
- def_node_matcher
|
24
24
|
- def_node_search
|
25
25
|
|
26
|
+
Naming/InclusiveLanguage:
|
27
|
+
FlaggedTerms:
|
28
|
+
whitelist:
|
29
|
+
Suggestions:
|
30
|
+
- allowlist
|
31
|
+
blacklist:
|
32
|
+
Suggestions:
|
33
|
+
- denylist
|
34
|
+
master:
|
35
|
+
AllowedRegex:
|
36
|
+
- 'blob/master/'
|
37
|
+
- 'master \(unreleased\)'
|
38
|
+
|
26
39
|
Style/FormatStringToken:
|
27
40
|
# Because we parse a lot of source codes from strings. Percent arrays
|
28
41
|
# look like unannotated format string tokens to this cop.
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,40 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.14.0 (2021-07-03)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#133](https://github.com/rubocop/rubocop-minitest/issues/133): Add new `Minitest/UnreachableAssertion` cop. ([@koic][])
|
10
|
+
|
11
|
+
## 0.13.0 (2021-06-20)
|
12
|
+
|
13
|
+
### New features
|
14
|
+
|
15
|
+
* [#136](https://github.com/rubocop/rubocop-minitest/pull/136): Support Active Support's `test` method for `Minitest/MultipleAssertions` and `Minitest/NoAssertions` cops. ([@koic][])
|
16
|
+
|
17
|
+
## 0.12.1 (2021-04-25)
|
18
|
+
|
19
|
+
### Bug fixes
|
20
|
+
|
21
|
+
* [#131](https://github.com/rubocop/rubocop-minitest/issues/131): Fix an error for `Minitest/MultipleAssertions` and fixes a false positive for `test` block. ([@koic][])
|
22
|
+
|
23
|
+
## 0.12.0 (2021-04-23)
|
24
|
+
|
25
|
+
### New features
|
26
|
+
|
27
|
+
* [#124](https://github.com/rubocop/rubocop-minitest/pull/124): Add new `Minitest/NoAssertions` cop. ([@ghiculescu][])
|
28
|
+
|
29
|
+
### Changes
|
30
|
+
|
31
|
+
* [#129](https://github.com/rubocop/rubocop-minitest/pull/129): Drop Ruby 2.4 support. ([@koic][])
|
32
|
+
|
33
|
+
## 0.11.1 (2021-03-31)
|
34
|
+
|
35
|
+
### Changes
|
36
|
+
|
37
|
+
* [#126](https://github.com/rubocop/rubocop-minitest/issues/126): Mark `Minitest/AssertWithExpectedArgument` as unsafe. ([@koic][])
|
38
|
+
|
5
39
|
## 0.11.0 (2021-03-22)
|
6
40
|
|
7
41
|
### New features
|
data/Gemfile
CHANGED
data/config/default.yml
CHANGED
@@ -97,6 +97,7 @@ Minitest/AssertTruthy:
|
|
97
97
|
Minitest/AssertWithExpectedArgument:
|
98
98
|
Description: 'This cop tries to detect when a user accidentally used `assert` when they meant to use `assert_equal`.'
|
99
99
|
Enabled: pending
|
100
|
+
Safe: false
|
100
101
|
VersionAdded: '0.11'
|
101
102
|
|
102
103
|
Minitest/GlobalExpectations:
|
@@ -117,6 +118,11 @@ Minitest/MultipleAssertions:
|
|
117
118
|
VersionAdded: '0.10'
|
118
119
|
Max: 3
|
119
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
|
+
|
120
126
|
Minitest/RefuteEmpty:
|
121
127
|
Description: 'This cop enforces to use `refute_empty` instead of using `refute(object.empty?)`.'
|
122
128
|
StyleGuide: 'https://minitest.rubystyle.guide#refute-empty'
|
@@ -188,6 +194,11 @@ Minitest/TestMethodName:
|
|
188
194
|
Enabled: 'pending'
|
189
195
|
VersionAdded: '0.10'
|
190
196
|
|
197
|
+
Minitest/UnreachableAssertion:
|
198
|
+
Description: 'This cop checks for an `assert_raises` block containing any unreachable assertions.'
|
199
|
+
Enabled: pending
|
200
|
+
VersionAdded: '0.14'
|
201
|
+
|
191
202
|
Minitest/UnspecifiedException:
|
192
203
|
Description: 'This cop checks for a specified error in `assert_raises`.'
|
193
204
|
StyleGuide: 'https://minitest.rubystyle.guide#unspecified-exception'
|
data/docs/antora.yml
CHANGED
@@ -32,6 +32,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
|
|
32
32
|
* xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
|
33
33
|
* xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
|
34
34
|
* xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
|
35
|
+
* xref:cops_minitest.adoc#minitestnoassertions[Minitest/NoAssertions]
|
35
36
|
* xref:cops_minitest.adoc#minitestrefuteempty[Minitest/RefuteEmpty]
|
36
37
|
* xref:cops_minitest.adoc#minitestrefuteequal[Minitest/RefuteEqual]
|
37
38
|
* xref:cops_minitest.adoc#minitestrefutefalse[Minitest/RefuteFalse]
|
@@ -44,6 +45,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
|
|
44
45
|
* xref:cops_minitest.adoc#minitestrefutepathexists[Minitest/RefutePathExists]
|
45
46
|
* xref:cops_minitest.adoc#minitestrefuterespondto[Minitest/RefuteRespondTo]
|
46
47
|
* xref:cops_minitest.adoc#minitesttestmethodname[Minitest/TestMethodName]
|
48
|
+
* xref:cops_minitest.adoc#minitestunreachableassertion[Minitest/UnreachableAssertion]
|
47
49
|
* xref:cops_minitest.adoc#minitestunspecifiedexception[Minitest/UnspecifiedException]
|
48
50
|
|
49
51
|
// END_COP_LIST
|
@@ -447,7 +447,7 @@ assert(actual, 'message')
|
|
447
447
|
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
448
448
|
|
449
449
|
| Pending
|
450
|
-
|
|
450
|
+
| No
|
451
451
|
| No
|
452
452
|
| 0.11
|
453
453
|
| -
|
@@ -456,6 +456,9 @@ assert(actual, 'message')
|
|
456
456
|
This cop tries to detect when a user accidentally used
|
457
457
|
`assert` when they meant to use `assert_equal`.
|
458
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
|
+
|
459
462
|
=== Examples
|
460
463
|
|
461
464
|
[source,ruby]
|
@@ -622,6 +625,38 @@ end
|
|
622
625
|
| Integer
|
623
626
|
|===
|
624
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
|
+
|
625
660
|
== Minitest/RefuteEmpty
|
626
661
|
|
627
662
|
|===
|
@@ -1018,6 +1053,38 @@ class FooTest < Minitest::Test
|
|
1018
1053
|
end
|
1019
1054
|
----
|
1020
1055
|
|
1056
|
+
== Minitest/UnreachableAssertion
|
1057
|
+
|
1058
|
+
|===
|
1059
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
1060
|
+
|
1061
|
+
| Pending
|
1062
|
+
| Yes
|
1063
|
+
| No
|
1064
|
+
| 0.14
|
1065
|
+
| -
|
1066
|
+
|===
|
1067
|
+
|
1068
|
+
This cop checks for `assert_raises` has an assertion method at
|
1069
|
+
the bottom of block because the assertion will be never reached.
|
1070
|
+
|
1071
|
+
=== Examples
|
1072
|
+
|
1073
|
+
[source,ruby]
|
1074
|
+
----
|
1075
|
+
# bad
|
1076
|
+
assert_raises FooError do
|
1077
|
+
obj.occur_error
|
1078
|
+
assert_equal('foo', obj.bar) # Never asserted.
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
# good
|
1082
|
+
assert_raises FooError do
|
1083
|
+
obj.occur_error
|
1084
|
+
end
|
1085
|
+
assert_equal('foo', obj.bar)
|
1086
|
+
----
|
1087
|
+
|
1021
1088
|
== Minitest/UnspecifiedException
|
1022
1089
|
|
1023
1090
|
|===
|
@@ -14,8 +14,9 @@ module RuboCop
|
|
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)`.'
|
@@ -32,15 +33,9 @@ module RuboCop
|
|
32
33
|
args = matchers.map(&:source).join(', ')
|
33
34
|
|
34
35
|
message = format(MSG, literal: literal.source, arguments: args)
|
35
|
-
add_offense(node, message: message)
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def autocorrect(node)
|
40
|
-
assert_equal_with_empty_literal(node) do |_literal, matchers|
|
41
|
-
object = matchers.first
|
36
|
+
add_offense(node, message: message) do |corrector|
|
37
|
+
object = matchers.first
|
42
38
|
|
43
|
-
lambda do |corrector|
|
44
39
|
corrector.replace(node.loc.selector, 'assert_empty')
|
45
40
|
corrector.replace(first_and_second_arguments_range(node), object.source)
|
46
41
|
end
|
@@ -15,8 +15,9 @@ module RuboCop
|
|
15
15
|
# assert_in_delta(0.2, actual)
|
16
16
|
# assert_in_delta(0.2, actual, 0.001, 'message')
|
17
17
|
#
|
18
|
-
class AssertInDelta <
|
18
|
+
class AssertInDelta < Base
|
19
19
|
include InDeltaMixin
|
20
|
+
extend AutoCorrector
|
20
21
|
|
21
22
|
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
22
23
|
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
# assert_includes(collection, object)
|
16
16
|
# assert_includes(collection, object, 'message')
|
17
17
|
#
|
18
|
-
class AssertIncludes <
|
18
|
+
class AssertIncludes < Base
|
19
19
|
extend MinitestCopRule
|
20
20
|
|
21
21
|
define_rule :assert, target_method: :include?, preferred_method: :assert_includes
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
# assert_instance_of(Class, object)
|
16
16
|
# assert_instance_of(Class, object, 'message')
|
17
17
|
#
|
18
|
-
class AssertInstanceOf <
|
18
|
+
class AssertInstanceOf < Base
|
19
19
|
extend MinitestCopRule
|
20
20
|
|
21
21
|
define_rule :assert, target_method: :instance_of?, inverse: true
|
@@ -15,8 +15,9 @@ module RuboCop
|
|
15
15
|
# assert_nil(actual)
|
16
16
|
# assert_nil(actual, 'message')
|
17
17
|
#
|
18
|
-
class AssertNil <
|
18
|
+
class AssertNil < Base
|
19
19
|
include ArgumentRangeHelper
|
20
|
+
extend AutoCorrector
|
20
21
|
|
21
22
|
MSG = 'Prefer using `assert_nil(%<arguments>s)` over ' \
|
22
23
|
'`assert_equal(nil, %<arguments>s)`.'
|
@@ -32,17 +33,9 @@ module RuboCop
|
|
32
33
|
|
33
34
|
arguments = [actual.source, message&.source].compact.join(', ')
|
34
35
|
|
35
|
-
add_offense(node, message: format(MSG, arguments: arguments))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def autocorrect(node)
|
40
|
-
lambda do |corrector|
|
41
|
-
assert_equal_with_nil(node) do |actual|
|
36
|
+
add_offense(node, message: format(MSG, arguments: arguments)) do |corrector|
|
42
37
|
corrector.replace(node.loc.selector, 'assert_nil')
|
43
|
-
corrector.replace(
|
44
|
-
first_and_second_arguments_range(node), actual.source
|
45
|
-
)
|
38
|
+
corrector.replace(first_and_second_arguments_range(node), actual.source)
|
46
39
|
end
|
47
40
|
end
|
48
41
|
end
|
@@ -15,7 +15,9 @@ module RuboCop
|
|
15
15
|
# assert_path_exists(path)
|
16
16
|
# assert_path_exists(path, 'message')
|
17
17
|
#
|
18
|
-
class AssertPathExists <
|
18
|
+
class AssertPathExists < Base
|
19
|
+
extend AutoCorrector
|
20
|
+
|
19
21
|
MSG = 'Prefer using `%<good_method>s` over `%<bad_method>s`.'
|
20
22
|
RESTRICT_ON_SEND = %i[assert].freeze
|
21
23
|
|
@@ -32,17 +34,8 @@ module RuboCop
|
|
32
34
|
good_method = build_good_method(path, failure_message)
|
33
35
|
message = format(MSG, good_method: good_method, bad_method: node.source)
|
34
36
|
|
35
|
-
add_offense(node, message: message)
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def autocorrect(node)
|
40
|
-
assert_file_exists(node) do |path, failure_message|
|
41
|
-
failure_message = failure_message.first
|
42
|
-
|
43
|
-
lambda do |corrector|
|
44
|
-
replacement = build_good_method(path, failure_message)
|
45
|
-
corrector.replace(node, replacement)
|
37
|
+
add_offense(node, message: message) do |corrector|
|
38
|
+
corrector.replace(node, good_method)
|
46
39
|
end
|
47
40
|
end
|
48
41
|
end
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
# assert_respond_to(object, :do_something, 'message')
|
18
18
|
# assert_respond_to(self, :do_something)
|
19
19
|
#
|
20
|
-
class AssertRespondTo <
|
20
|
+
class AssertRespondTo < Base
|
21
21
|
extend MinitestCopRule
|
22
22
|
|
23
23
|
define_rule :assert, target_method: :respond_to?
|
@@ -13,7 +13,9 @@ module RuboCop
|
|
13
13
|
# # good
|
14
14
|
# assert_silent { puts object.do_something }
|
15
15
|
#
|
16
|
-
class AssertSilent <
|
16
|
+
class AssertSilent < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
17
19
|
MSG = 'Prefer using `assert_silent` over `assert_output("", "")`.'
|
18
20
|
|
19
21
|
def_node_matcher :assert_silent_candidate?, <<~PATTERN
|
@@ -25,12 +27,12 @@ module RuboCop
|
|
25
27
|
PATTERN
|
26
28
|
|
27
29
|
def on_block(node)
|
28
|
-
|
29
|
-
|
30
|
+
return unless assert_silent_candidate?(node)
|
31
|
+
|
32
|
+
send_node = node.send_node
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
corrector.replace(node, 'assert_silent')
|
34
|
+
add_offense(send_node) do |corrector|
|
35
|
+
corrector.replace(send_node, 'assert_silent')
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|