rubocop-minitest 0.7.0 → 0.10.1
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 +0 -3
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +0 -7
- data/CHANGELOG.md +58 -0
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/Rakefile +29 -0
- data/config/default.yml +96 -16
- data/docs/antora.yml +7 -0
- data/docs/modules/ROOT/nav.adoc +6 -0
- data/docs/modules/ROOT/pages/cops.adoc +37 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +1014 -0
- data/docs/modules/ROOT/pages/index.adoc +5 -0
- data/docs/modules/ROOT/pages/installation.adoc +15 -0
- data/docs/modules/ROOT/pages/usage.adoc +32 -0
- data/{manual → legacy-docs}/cops.md +0 -0
- data/{manual → legacy-docs}/cops_minitest.md +7 -5
- data/{manual → legacy-docs}/index.md +0 -0
- data/{manual → legacy-docs}/installation.md +0 -0
- data/{manual → legacy-docs}/usage.md +0 -0
- data/lib/rubocop/cop/generator.rb +56 -0
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +15 -0
- data/lib/rubocop/cop/minitest/assert_equal.rb +2 -31
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/assert_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/assert_output.rb +49 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/assert_silent.rb +45 -0
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +43 -0
- data/lib/rubocop/cop/minitest/global_expectations.rb +49 -28
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +52 -0
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +63 -0
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/refute_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +70 -0
- data/lib/rubocop/cop/minitest/unspecified_exception.rb +36 -0
- data/lib/rubocop/cop/minitest_cops.rb +15 -0
- data/lib/rubocop/cop/mixin/argument_range_helper.rb +10 -0
- data/lib/rubocop/cop/mixin/in_delta_mixin.rb +50 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +1 -3
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +84 -0
- data/lib/rubocop/minitest/version.rb +1 -1
- data/mkdocs.yml +2 -2
- data/relnotes/v0.10.0.md +21 -0
- data/relnotes/v0.10.1.md +5 -0
- data/relnotes/v0.8.0.md +12 -0
- data/relnotes/v0.8.1.md +5 -0
- data/relnotes/v0.9.0.md +10 -0
- data/rubocop-minitest.gemspec +4 -4
- data/tasks/cops_documentation.rake +83 -54
- data/tasks/cut_release.rake +16 -0
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b6cb0236ad583a81b4b3d12fdf4bf9d83cb53cfb565973fd54e5ae8a9dbd487
|
4
|
+
data.tar.gz: 6e41c1f11d6e20f29fbff140a71bf44c6e67db274b6cc30531220839e9c903b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ea2746f324798c678144e938f35e392dc9062d4ccdbd184726d0dd122ddd564c993db2ab20c7d45f989f542adca8e692e40f6d2edeef1201e7415ab2c78b625
|
7
|
+
data.tar.gz: 8448666265020b303754a109336f055402bdd375b020261a6d46f61d682c979e1e42edff409124bb9ee2cbc43744383f260c6b5908f55737c7b2fdefdf4856de
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -14,10 +14,3 @@ Metrics/AbcSize:
|
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
15
15
|
Metrics/MethodLength:
|
16
16
|
Max: 14
|
17
|
-
|
18
|
-
# Offense count: 40
|
19
|
-
# Cop supports --auto-correct.
|
20
|
-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
21
|
-
# URISchemes: http, https
|
22
|
-
Layout/LineLength:
|
23
|
-
Max: 100
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,61 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.10.1 (2020-07-25)
|
6
|
+
|
7
|
+
### Bug fixes
|
8
|
+
|
9
|
+
* [#106](https://github.com/rubocop-hq/rubocop-minitest/issues/106): Fix an error for `Minitest/AssertOutput` when using gvar at top level. ([@koic][])
|
10
|
+
|
11
|
+
## 0.10.0 (2020-07-12)
|
12
|
+
|
13
|
+
### New features
|
14
|
+
|
15
|
+
* [#92](https://github.com/rubocop-hq/rubocop-minitest/pull/92): Add new `Minitest/LiteralAsActualArgument` cop. ([@fatkodima][], [@tsmmark][])
|
16
|
+
* [#95](https://github.com/rubocop-hq/rubocop-minitest/pull/95): Add new `Minitest/AssertionInLifecycleHook` cop. ([@fatkodima][])
|
17
|
+
* [#91](https://github.com/rubocop-hq/rubocop-minitest/pull/91): Add new `Minitest/AssertInDelta` and `Minitest/RefuteInDelta` cops. ([@fatkodima][])
|
18
|
+
* [#89](https://github.com/rubocop-hq/rubocop-minitest/pull/89): Add new `Minitest/TestMethodName` cop. ([@fatkodima][])
|
19
|
+
* [#83](https://github.com/rubocop-hq/rubocop-minitest/pull/83): New cops `AssertPathExists` and `RefutePathExists` check for use of `assert_path_exists`/`refute_path_exists` instead of `assert(File.exist?(path))`/`refute(File.exist?(path))`. ([@fatkodima][])
|
20
|
+
* [#88](https://github.com/rubocop-hq/rubocop-minitest/pull/88): Add new `Minitest/MultipleAssertions` cop. ([@fatkodima][])
|
21
|
+
* [#87](https://github.com/rubocop-hq/rubocop-minitest/pull/87): Add new `Minitest/AssertSilent` cop. ([@fatkodima][])
|
22
|
+
* [#96](https://github.com/rubocop-hq/rubocop-minitest/pull/96): Add new `Minitest/UnspecifiedException` cop. ([@fatkodima][])
|
23
|
+
* [#98](https://github.com/rubocop-hq/rubocop-minitest/pull/98): Add new `Minitest/AssertOutput` cop. ([@fatkodima][])
|
24
|
+
* [#84](https://github.com/rubocop-hq/rubocop-minitest/pull/84): New cops `AssertKindOf` and `RefuteKindOf` check for use of `assert_kind_of`/`refute_kind_of` instead of `assert(foo.kind_of?(Class))`/`refute(foo.kind_of?(Class))`. ([@fatkodima][])
|
25
|
+
* [#85](https://github.com/rubocop-hq/rubocop-minitest/pull/85): Add autocorrect to `Rails/AssertEmptyLiteral` cop. ([@fatkodima][])
|
26
|
+
|
27
|
+
### Changes
|
28
|
+
|
29
|
+
* [#104](https://github.com/rubocop-hq/rubocop-minitest/pull/104): Require RuboCop 0.87 or higher. ([@koic][])
|
30
|
+
|
31
|
+
## 0.9.0 (2020-04-13)
|
32
|
+
|
33
|
+
### Bug fixes
|
34
|
+
|
35
|
+
* [#75](https://github.com/rubocop-hq/rubocop-minitest/issues/75): Fix a false negative for `Minitest/GlobalExpectations` when using global expectation methods with no arguments. ([@koic][])
|
36
|
+
|
37
|
+
### Changes
|
38
|
+
|
39
|
+
* [#73](https://github.com/rubocop-hq/rubocop-minitest/issues/73): The Minitest department works on file names end with `_test.rb` by default. ([@koic][])
|
40
|
+
* [#77](https://github.com/rubocop-hq/rubocop-minitest/pull/77): **(BREAKING)** Drop support for Ruby 2.3. ([@koic][])
|
41
|
+
|
42
|
+
## 0.8.1 (2020-04-06)
|
43
|
+
|
44
|
+
### Bug fixes
|
45
|
+
|
46
|
+
* [#72](https://github.com/rubocop-hq/rubocop-minitest/pull/72): Fix some false negatives for `Minitest/GlobalExpectations`. ([@andrykonchin][])
|
47
|
+
|
48
|
+
## 0.8.0 (2020-03-24)
|
49
|
+
|
50
|
+
### New features
|
51
|
+
|
52
|
+
* [#66](https://github.com/rubocop-hq/rubocop-minitest/issues/66): Support all expectations of `Minitest::Expectations` for `Minitest/GlobalExpectations` cop. ([@koic][])
|
53
|
+
|
54
|
+
### Bug fixes
|
55
|
+
|
56
|
+
* [#60](https://github.com/rubocop-hq/rubocop-minitest/issues/60): Fix `Minitest/GlobalExpectations` autocorrection for chained methods. ([@tejasbubane][])
|
57
|
+
* [#69](https://github.com/rubocop-hq/rubocop-minitest/pull/69): Fix a false negative for `Minitest/GlobalExpectations` cop when using a variable or a hash index for receiver. ([@koic][])
|
58
|
+
* [#71](https://github.com/rubocop-hq/rubocop-minitest/pull/71): Fix a false negative for `Minitest/AssertEqual` when an argument is enclosed in redundant parentheses. ([@koic][])
|
59
|
+
|
5
60
|
## 0.7.0 (2020-03-09)
|
6
61
|
|
7
62
|
### New features
|
@@ -107,3 +162,6 @@
|
|
107
162
|
[@abhaynikam]: https://github.com/abhaynikam
|
108
163
|
[@herwinw]: https://github.com/herwinw
|
109
164
|
[@fsateler]: https://github.com/fsateler
|
165
|
+
[@andrykonchin]: https://github.com/andrykonchin
|
166
|
+
[@fatkodima]: https://github.com/fatkodima
|
167
|
+
[@tsmmark]: https://github.com/tsmmark
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -62,7 +62,7 @@ end
|
|
62
62
|
|
63
63
|
All cops are located under
|
64
64
|
[`lib/rubocop/cop/minitest`](lib/rubocop/cop/minitest), and contain
|
65
|
-
examples/documentation. The documentation is published [here](https://docs.rubocop.org/
|
65
|
+
examples/documentation. The documentation is published [here](https://docs.rubocop.org/rubocop-minitest/).
|
66
66
|
|
67
67
|
In your `.rubocop.yml`, you may treat the Minitest cops just like any other
|
68
68
|
cop. For example:
|
@@ -75,7 +75,7 @@ Minitest/AssertNil:
|
|
75
75
|
|
76
76
|
## Documentation
|
77
77
|
|
78
|
-
You can read a lot more about RuboCop Minitest in its [official docs](https://docs.rubocop.org/
|
78
|
+
You can read a lot more about RuboCop Minitest in its [official docs](https://docs.rubocop.org/rubocop-minitest/).
|
79
79
|
|
80
80
|
## Contributing
|
81
81
|
|
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ end
|
|
15
15
|
|
16
16
|
require 'rubocop/rake_task'
|
17
17
|
require 'rake/testtask'
|
18
|
+
require_relative 'lib/rubocop/cop/generator'
|
18
19
|
|
19
20
|
Rake::TestTask.new do |t|
|
20
21
|
t.libs << 'test'
|
@@ -36,3 +37,31 @@ task default: %i[
|
|
36
37
|
test
|
37
38
|
internal_investigation
|
38
39
|
]
|
40
|
+
|
41
|
+
desc 'Generate a new cop template'
|
42
|
+
task :new_cop, [:cop] do |_task, args|
|
43
|
+
require 'rubocop'
|
44
|
+
|
45
|
+
cop_name = args.fetch(:cop) do
|
46
|
+
warn 'usage: bundle exec rake new_cop[Department/Name]'
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
|
50
|
+
github_user = `git config github.user`.chop
|
51
|
+
github_user = 'your_id' if github_user.empty?
|
52
|
+
|
53
|
+
generator = RuboCop::Cop::Generator.new(cop_name, github_user)
|
54
|
+
|
55
|
+
generator.write_source
|
56
|
+
generator.write_test
|
57
|
+
generator.inject_require(root_file_path: 'lib/rubocop/cop/minitest_cops.rb')
|
58
|
+
generator.inject_config(config_file_path: 'config/default.yml', version_added: bump_minor_version)
|
59
|
+
|
60
|
+
puts generator.todo
|
61
|
+
end
|
62
|
+
|
63
|
+
def bump_minor_version
|
64
|
+
major, minor, _patch = RuboCop::Minitest::VERSION.split('.')
|
65
|
+
|
66
|
+
"#{major}.#{minor.succ}"
|
67
|
+
end
|
data/config/default.yml
CHANGED
@@ -2,109 +2,189 @@ Minitest:
|
|
2
2
|
Enabled: true
|
3
3
|
Include:
|
4
4
|
- '**/test/**/*'
|
5
|
+
- '**/*_test.rb'
|
5
6
|
|
6
7
|
Minitest/AssertEmpty:
|
7
8
|
Description: 'This cop enforces the test to use `assert_empty` instead of using `assert(object.empty?)`.'
|
8
|
-
StyleGuide: 'https://
|
9
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-empty'
|
9
10
|
Enabled: true
|
10
11
|
VersionAdded: '0.2'
|
11
12
|
|
12
13
|
Minitest/AssertEmptyLiteral:
|
13
14
|
Description: 'This cop enforces the test to use `assert_empty` instead of using `assert([], object)` or `assert({}, object)`.'
|
14
15
|
Enabled: true
|
16
|
+
SafeAutoCorrect: false
|
15
17
|
VersionAdded: '0.5'
|
18
|
+
VersionChanged: '0.10'
|
16
19
|
|
17
20
|
Minitest/AssertEqual:
|
18
21
|
Description: 'This cop enforces the test to use `assert_equal` instead of using `assert(expected == actual)`.'
|
19
|
-
StyleGuide: 'https://
|
22
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-equal-arguments-order'
|
20
23
|
Enabled: true
|
21
24
|
VersionAdded: '0.4'
|
22
25
|
|
26
|
+
Minitest/AssertInDelta:
|
27
|
+
Description: 'This cop enforces the test to use `assert_in_delta` instead of using `assert_equal` to compare floats.'
|
28
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#assert-in-delta'
|
29
|
+
Enabled: 'pending'
|
30
|
+
VersionAdded: '0.10'
|
31
|
+
|
32
|
+
Minitest/AssertionInLifecycleHook:
|
33
|
+
Description: 'This cop checks for usage of assertions in lifecycle hooks.'
|
34
|
+
Enabled: 'pending'
|
35
|
+
VersionAdded: '0.10'
|
36
|
+
|
23
37
|
Minitest/AssertMatch:
|
24
38
|
Description: 'This cop enforces the test to use `assert_match` instead of using `assert(matcher.match(object))`.'
|
25
|
-
StyleGuide: 'https://
|
39
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-match'
|
26
40
|
Enabled: true
|
27
41
|
VersionAdded: '0.6'
|
28
42
|
|
29
43
|
Minitest/AssertIncludes:
|
30
44
|
Description: 'This cop enforces the test to use `assert_includes` instead of using `assert(collection.include?(object))`.'
|
31
|
-
StyleGuide: 'https://
|
45
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-includes'
|
32
46
|
Enabled: true
|
33
47
|
VersionAdded: '0.2'
|
34
48
|
|
35
49
|
Minitest/AssertInstanceOf:
|
36
50
|
Description: 'This cop enforces the test to use `assert_instance_of(Class, object)` over `assert(object.instance_of?(Class))`'
|
37
|
-
StyleGuide: 'https://
|
51
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-instance-of'
|
38
52
|
Enabled: true
|
39
53
|
VersionAdded: '0.4'
|
40
54
|
|
55
|
+
Minitest/AssertKindOf:
|
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-hq/minitest-style-guide#assert-kind-of'
|
58
|
+
Enabled: 'pending'
|
59
|
+
VersionAdded: '0.10'
|
60
|
+
|
41
61
|
Minitest/AssertNil:
|
42
62
|
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)`.'
|
43
|
-
StyleGuide: 'https://
|
63
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-nil'
|
44
64
|
Enabled: true
|
45
65
|
VersionAdded: '0.1'
|
46
66
|
|
67
|
+
Minitest/AssertOutput:
|
68
|
+
Description: 'This cop checks for opportunities to use `assert_output`.'
|
69
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#assert-output'
|
70
|
+
Enabled: 'pending'
|
71
|
+
VersionAdded: '0.10'
|
72
|
+
|
73
|
+
Minitest/AssertPathExists:
|
74
|
+
Description: 'This cop enforces the test to use `assert_path_exists` instead of using `assert(File.exist?(path))`.'
|
75
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#assert-path-exists'
|
76
|
+
Enabled: 'pending'
|
77
|
+
VersionAdded: '0.10'
|
78
|
+
|
47
79
|
Minitest/AssertRespondTo:
|
48
80
|
Description: 'This cop enforces the test to use `assert_respond_to(object, :do_something)` over `assert(object.respond_to?(:do_something))`.'
|
49
|
-
StyleGuide: 'https://
|
81
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-responds-to-method'
|
50
82
|
Enabled: true
|
51
83
|
VersionAdded: '0.3'
|
52
84
|
|
85
|
+
Minitest/AssertSilent:
|
86
|
+
Description: "This cop enforces the test to use `assert_silent { ... }` instead of using `assert_output('', '') { ... }`."
|
87
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-silent'
|
88
|
+
Enabled: 'pending'
|
89
|
+
VersionAdded: '0.10'
|
90
|
+
|
53
91
|
Minitest/AssertTruthy:
|
54
92
|
Description: 'This cop enforces the test to use `assert(actual)` instead of using `assert_equal(true, actual)`.'
|
55
|
-
StyleGuide: 'https://
|
93
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-truthy'
|
56
94
|
Enabled: true
|
57
95
|
VersionAdded: '0.2'
|
58
96
|
|
59
97
|
Minitest/GlobalExpectations:
|
60
98
|
Description: 'This cop checks for deprecated global expectations.'
|
99
|
+
StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
|
61
100
|
Enabled: true
|
62
101
|
VersionAdded: '0.7'
|
63
102
|
|
103
|
+
Minitest/LiteralAsActualArgument:
|
104
|
+
Description: 'This cop enforces correct order of `expected` and `actual` arguments for `assert_equal`.'
|
105
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#assert-equal-arguments-order'
|
106
|
+
Enabled: 'pending'
|
107
|
+
VersionAdded: '0.10'
|
108
|
+
|
109
|
+
Minitest/MultipleAssertions:
|
110
|
+
Description: 'This cop checks if test cases contain too many assertion calls.'
|
111
|
+
Enabled: 'pending'
|
112
|
+
VersionAdded: '0.10'
|
113
|
+
Max: 3
|
114
|
+
|
64
115
|
Minitest/RefuteEmpty:
|
65
116
|
Description: 'This cop enforces to use `refute_empty` instead of using `refute(object.empty?)`.'
|
66
|
-
StyleGuide: 'https://
|
117
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-empty'
|
67
118
|
Enabled: true
|
68
119
|
VersionAdded: '0.3'
|
69
120
|
|
70
121
|
Minitest/RefuteEqual:
|
71
122
|
Description: 'Check if your test uses `refute_equal` instead of `assert(expected != object)` or `assert(! expected == object))`.'
|
72
|
-
StyleGuide: 'https://
|
123
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-equal'
|
73
124
|
Enabled: true
|
74
125
|
VersionAdded: '0.3'
|
75
126
|
|
76
127
|
Minitest/RefuteFalse:
|
77
128
|
Description: 'Check if your test uses `refute(actual)` instead of `assert_equal(false, actual)`.'
|
78
|
-
StyleGuide: 'https://
|
129
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-false'
|
79
130
|
Enabled: true
|
80
131
|
VersionAdded: '0.3'
|
81
132
|
|
133
|
+
Minitest/RefuteInDelta:
|
134
|
+
Description: 'This cop enforces the test to use `refute_in_delta` instead of using `refute_equal` to compare floats.'
|
135
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#refute-in-delta'
|
136
|
+
Enabled: 'pending'
|
137
|
+
VersionAdded: '0.10'
|
138
|
+
|
82
139
|
Minitest/RefuteIncludes:
|
83
140
|
Description: 'This cop enforces the test to use `refute_includes` instead of using `refute(collection.include?(object))`.'
|
84
|
-
StyleGuide: 'https://
|
141
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-includes'
|
85
142
|
Enabled: true
|
86
143
|
VersionAdded: '0.3'
|
87
144
|
|
88
145
|
Minitest/RefuteMatch:
|
89
146
|
Description: 'This cop enforces the test to use `refute_match` instead of using `refute(matcher.match(object))`.'
|
90
|
-
StyleGuide: 'https://
|
147
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-match'
|
91
148
|
Enabled: true
|
92
149
|
VersionAdded: '0.6'
|
93
150
|
|
94
151
|
Minitest/RefuteInstanceOf:
|
95
152
|
Description: 'This cop enforces the test to use `refute_instance_of(Class, object)` over `refute(object.instance_of?(Class))`.'
|
96
|
-
StyleGuide: 'https://
|
153
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-instance-of'
|
97
154
|
Enabled: true
|
98
155
|
VersionAdded: '0.4'
|
99
156
|
|
157
|
+
Minitest/RefuteKindOf:
|
158
|
+
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-hq/minitest-style-guide#refute-kind-of'
|
160
|
+
Enabled: 'pending'
|
161
|
+
VersionAdded: '0.10'
|
162
|
+
|
100
163
|
Minitest/RefuteNil:
|
101
164
|
Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)`.'
|
102
|
-
StyleGuide: 'https://
|
165
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-nil'
|
103
166
|
Enabled: true
|
104
167
|
VersionAdded: '0.2'
|
105
168
|
|
169
|
+
Minitest/RefutePathExists:
|
170
|
+
Description: 'This cop enforces the test to use `refute_path_exists` instead of using `refute(File.exist?(path))`.'
|
171
|
+
StyleGuide: 'https://minitest.rubystyle.guide/#refute-path-exists'
|
172
|
+
Enabled: 'pending'
|
173
|
+
VersionAdded: '0.10'
|
174
|
+
|
106
175
|
Minitest/RefuteRespondTo:
|
107
176
|
Description: 'This cop enforces the test to use `refute_respond_to(object, :do_something)` over `refute(object.respond_to?(:do_something))`.'
|
108
|
-
StyleGuide: 'https://
|
177
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-respond-to'
|
109
178
|
Enabled: true
|
110
179
|
VersionAdded: '0.4'
|
180
|
+
|
181
|
+
Minitest/TestMethodName:
|
182
|
+
Description: 'This cop enforces that test method names start with `test_` prefix.'
|
183
|
+
Enabled: 'pending'
|
184
|
+
VersionAdded: '0.10'
|
185
|
+
|
186
|
+
Minitest/UnspecifiedException:
|
187
|
+
Description: 'This cop checks for a specified error in `assert_raises`.'
|
188
|
+
StyleGuide: 'https://minitest.rubystyle.guide#unspecified-exception'
|
189
|
+
Enabled: 'pending'
|
190
|
+
VersionAdded: '0.10'
|
data/docs/antora.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
// START_COP_LIST
|
2
|
+
|
3
|
+
= Department xref:cops_minitest.adoc[Minitest]
|
4
|
+
|
5
|
+
* xref:cops_minitest.adoc#minitestassertempty[Minitest/AssertEmpty]
|
6
|
+
* xref:cops_minitest.adoc#minitestassertemptyliteral[Minitest/AssertEmptyLiteral]
|
7
|
+
* xref:cops_minitest.adoc#minitestassertequal[Minitest/AssertEqual]
|
8
|
+
* xref:cops_minitest.adoc#minitestassertindelta[Minitest/AssertInDelta]
|
9
|
+
* xref:cops_minitest.adoc#minitestassertincludes[Minitest/AssertIncludes]
|
10
|
+
* xref:cops_minitest.adoc#minitestassertinstanceof[Minitest/AssertInstanceOf]
|
11
|
+
* xref:cops_minitest.adoc#minitestassertkindof[Minitest/AssertKindOf]
|
12
|
+
* xref:cops_minitest.adoc#minitestassertmatch[Minitest/AssertMatch]
|
13
|
+
* xref:cops_minitest.adoc#minitestassertnil[Minitest/AssertNil]
|
14
|
+
* xref:cops_minitest.adoc#minitestassertoutput[Minitest/AssertOutput]
|
15
|
+
* xref:cops_minitest.adoc#minitestassertpathexists[Minitest/AssertPathExists]
|
16
|
+
* xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo]
|
17
|
+
* xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent]
|
18
|
+
* xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
|
19
|
+
* xref:cops_minitest.adoc#minitestassertioninlifecyclehook[Minitest/AssertionInLifecycleHook]
|
20
|
+
* xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
|
21
|
+
* xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
|
22
|
+
* xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
|
23
|
+
* xref:cops_minitest.adoc#minitestrefuteempty[Minitest/RefuteEmpty]
|
24
|
+
* xref:cops_minitest.adoc#minitestrefuteequal[Minitest/RefuteEqual]
|
25
|
+
* xref:cops_minitest.adoc#minitestrefutefalse[Minitest/RefuteFalse]
|
26
|
+
* xref:cops_minitest.adoc#minitestrefuteindelta[Minitest/RefuteInDelta]
|
27
|
+
* xref:cops_minitest.adoc#minitestrefuteincludes[Minitest/RefuteIncludes]
|
28
|
+
* xref:cops_minitest.adoc#minitestrefuteinstanceof[Minitest/RefuteInstanceOf]
|
29
|
+
* xref:cops_minitest.adoc#minitestrefutekindof[Minitest/RefuteKindOf]
|
30
|
+
* xref:cops_minitest.adoc#minitestrefutematch[Minitest/RefuteMatch]
|
31
|
+
* xref:cops_minitest.adoc#minitestrefutenil[Minitest/RefuteNil]
|
32
|
+
* xref:cops_minitest.adoc#minitestrefutepathexists[Minitest/RefutePathExists]
|
33
|
+
* xref:cops_minitest.adoc#minitestrefuterespondto[Minitest/RefuteRespondTo]
|
34
|
+
* xref:cops_minitest.adoc#minitesttestmethodname[Minitest/TestMethodName]
|
35
|
+
* xref:cops_minitest.adoc#minitestunspecifiedexception[Minitest/UnspecifiedException]
|
36
|
+
|
37
|
+
// END_COP_LIST
|
@@ -0,0 +1,1014 @@
|
|
1
|
+
= Minitest
|
2
|
+
|
3
|
+
== Minitest/AssertEmpty
|
4
|
+
|
5
|
+
|===
|
6
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
7
|
+
|
8
|
+
| Enabled
|
9
|
+
| Yes
|
10
|
+
| Yes
|
11
|
+
| 0.2
|
12
|
+
| -
|
13
|
+
|===
|
14
|
+
|
15
|
+
This cop enforces the test to use `assert_empty`
|
16
|
+
instead of using `assert(object.empty?)`.
|
17
|
+
|
18
|
+
=== Examples
|
19
|
+
|
20
|
+
[source,ruby]
|
21
|
+
----
|
22
|
+
# bad
|
23
|
+
assert(object.empty?)
|
24
|
+
assert(object.empty?, 'message')
|
25
|
+
|
26
|
+
# good
|
27
|
+
assert_empty(object)
|
28
|
+
assert_empty(object, 'message')
|
29
|
+
----
|
30
|
+
|
31
|
+
=== References
|
32
|
+
|
33
|
+
* https://minitest.rubystyle.guide#assert-empty
|
34
|
+
|
35
|
+
== Minitest/AssertEmptyLiteral
|
36
|
+
|
37
|
+
|===
|
38
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
39
|
+
|
40
|
+
| Enabled
|
41
|
+
| Yes
|
42
|
+
| Yes (Unsafe)
|
43
|
+
| 0.5
|
44
|
+
| 0.10
|
45
|
+
|===
|
46
|
+
|
47
|
+
This cop enforces the test to use `assert_empty`
|
48
|
+
instead of using `assert([], object)`.
|
49
|
+
|
50
|
+
=== Examples
|
51
|
+
|
52
|
+
[source,ruby]
|
53
|
+
----
|
54
|
+
# bad
|
55
|
+
assert([], object)
|
56
|
+
assert({}, object)
|
57
|
+
|
58
|
+
# good
|
59
|
+
assert_empty(object)
|
60
|
+
----
|
61
|
+
|
62
|
+
== Minitest/AssertEqual
|
63
|
+
|
64
|
+
|===
|
65
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
66
|
+
|
67
|
+
| Enabled
|
68
|
+
| Yes
|
69
|
+
| Yes
|
70
|
+
| 0.4
|
71
|
+
| -
|
72
|
+
|===
|
73
|
+
|
74
|
+
This cop enforces the use of `assert_equal(expected, actual)`
|
75
|
+
over `assert(expected == actual)`.
|
76
|
+
|
77
|
+
=== Examples
|
78
|
+
|
79
|
+
[source,ruby]
|
80
|
+
----
|
81
|
+
# bad
|
82
|
+
assert("rubocop-minitest" == actual)
|
83
|
+
|
84
|
+
# good
|
85
|
+
assert_equal("rubocop-minitest", actual)
|
86
|
+
----
|
87
|
+
|
88
|
+
=== References
|
89
|
+
|
90
|
+
* https://minitest.rubystyle.guide#assert-equal-arguments-order
|
91
|
+
|
92
|
+
== Minitest/AssertInDelta
|
93
|
+
|
94
|
+
|===
|
95
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
96
|
+
|
97
|
+
| Pending
|
98
|
+
| Yes
|
99
|
+
| Yes
|
100
|
+
| 0.10
|
101
|
+
| -
|
102
|
+
|===
|
103
|
+
|
104
|
+
This cop enforces the test to use `assert_in_delta`
|
105
|
+
instead of using `assert_equal` to compare floats.
|
106
|
+
|
107
|
+
=== Examples
|
108
|
+
|
109
|
+
[source,ruby]
|
110
|
+
----
|
111
|
+
# bad
|
112
|
+
assert_equal(0.2, actual)
|
113
|
+
assert_equal(0.2, actual, 'message')
|
114
|
+
|
115
|
+
# good
|
116
|
+
assert_in_delta(0.2, actual)
|
117
|
+
assert_in_delta(0.2, actual, 0.001, 'message')
|
118
|
+
----
|
119
|
+
|
120
|
+
=== References
|
121
|
+
|
122
|
+
* https://minitest.rubystyle.guide/#assert-in-delta
|
123
|
+
|
124
|
+
== Minitest/AssertIncludes
|
125
|
+
|
126
|
+
|===
|
127
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
128
|
+
|
129
|
+
| Enabled
|
130
|
+
| Yes
|
131
|
+
| Yes
|
132
|
+
| 0.2
|
133
|
+
| -
|
134
|
+
|===
|
135
|
+
|
136
|
+
This cop enforces the test to use `assert_includes`
|
137
|
+
instead of using `assert(collection.include?(object))`.
|
138
|
+
|
139
|
+
=== Examples
|
140
|
+
|
141
|
+
[source,ruby]
|
142
|
+
----
|
143
|
+
# bad
|
144
|
+
assert(collection.include?(object))
|
145
|
+
assert(collection.include?(object), 'message')
|
146
|
+
|
147
|
+
# good
|
148
|
+
assert_includes(collection, object)
|
149
|
+
assert_includes(collection, object, 'message')
|
150
|
+
----
|
151
|
+
|
152
|
+
=== References
|
153
|
+
|
154
|
+
* https://minitest.rubystyle.guide#assert-includes
|
155
|
+
|
156
|
+
== Minitest/AssertInstanceOf
|
157
|
+
|
158
|
+
|===
|
159
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
160
|
+
|
161
|
+
| Enabled
|
162
|
+
| Yes
|
163
|
+
| Yes
|
164
|
+
| 0.4
|
165
|
+
| -
|
166
|
+
|===
|
167
|
+
|
168
|
+
This cop enforces the test to use `assert_instance_of(Class, object)`
|
169
|
+
over `assert(object.instance_of?(Class))`.
|
170
|
+
|
171
|
+
=== Examples
|
172
|
+
|
173
|
+
[source,ruby]
|
174
|
+
----
|
175
|
+
# bad
|
176
|
+
assert(object.instance_of?(Class))
|
177
|
+
assert(object.instance_of?(Class), 'message')
|
178
|
+
|
179
|
+
# good
|
180
|
+
assert_instance_of(Class, object)
|
181
|
+
assert_instance_of(Class, object, 'message')
|
182
|
+
----
|
183
|
+
|
184
|
+
=== References
|
185
|
+
|
186
|
+
* https://minitest.rubystyle.guide#assert-instance-of
|
187
|
+
|
188
|
+
== Minitest/AssertKindOf
|
189
|
+
|
190
|
+
|===
|
191
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
192
|
+
|
193
|
+
| Pending
|
194
|
+
| Yes
|
195
|
+
| Yes
|
196
|
+
| 0.10
|
197
|
+
| -
|
198
|
+
|===
|
199
|
+
|
200
|
+
This cop enforces the test to use `assert_kind_of(Class, object)`
|
201
|
+
over `assert(object.kind_of?(Class))`.
|
202
|
+
|
203
|
+
=== Examples
|
204
|
+
|
205
|
+
[source,ruby]
|
206
|
+
----
|
207
|
+
# bad
|
208
|
+
assert(object.kind_of?(Class))
|
209
|
+
assert(object.kind_of?(Class), 'message')
|
210
|
+
|
211
|
+
# good
|
212
|
+
assert_kind_of(Class, object)
|
213
|
+
assert_kind_of(Class, object, 'message')
|
214
|
+
----
|
215
|
+
|
216
|
+
=== References
|
217
|
+
|
218
|
+
* https://github.com/rubocop-hq/minitest-style-guide#assert-kind-of
|
219
|
+
|
220
|
+
== Minitest/AssertMatch
|
221
|
+
|
222
|
+
|===
|
223
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
224
|
+
|
225
|
+
| Enabled
|
226
|
+
| Yes
|
227
|
+
| Yes
|
228
|
+
| 0.6
|
229
|
+
| -
|
230
|
+
|===
|
231
|
+
|
232
|
+
This cop enforces the test to use `assert_match`
|
233
|
+
instead of using `assert(matcher.match(string))`.
|
234
|
+
|
235
|
+
=== Examples
|
236
|
+
|
237
|
+
[source,ruby]
|
238
|
+
----
|
239
|
+
# bad
|
240
|
+
assert(matcher.match(string))
|
241
|
+
assert(matcher.match(string), 'message')
|
242
|
+
|
243
|
+
# good
|
244
|
+
assert_match(regex, string)
|
245
|
+
assert_match(matcher, string, 'message')
|
246
|
+
----
|
247
|
+
|
248
|
+
=== References
|
249
|
+
|
250
|
+
* https://minitest.rubystyle.guide#assert-match
|
251
|
+
|
252
|
+
== Minitest/AssertNil
|
253
|
+
|
254
|
+
|===
|
255
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
256
|
+
|
257
|
+
| Enabled
|
258
|
+
| Yes
|
259
|
+
| Yes
|
260
|
+
| 0.1
|
261
|
+
| -
|
262
|
+
|===
|
263
|
+
|
264
|
+
This cop enforces the test to use `assert_nil`
|
265
|
+
instead of using `assert_equal(nil, something)`.
|
266
|
+
|
267
|
+
=== Examples
|
268
|
+
|
269
|
+
[source,ruby]
|
270
|
+
----
|
271
|
+
# bad
|
272
|
+
assert_equal(nil, actual)
|
273
|
+
assert_equal(nil, actual, 'message')
|
274
|
+
|
275
|
+
# good
|
276
|
+
assert_nil(actual)
|
277
|
+
assert_nil(actual, 'message')
|
278
|
+
----
|
279
|
+
|
280
|
+
=== References
|
281
|
+
|
282
|
+
* https://minitest.rubystyle.guide#assert-nil
|
283
|
+
|
284
|
+
== Minitest/AssertOutput
|
285
|
+
|
286
|
+
|===
|
287
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
288
|
+
|
289
|
+
| Pending
|
290
|
+
| Yes
|
291
|
+
| No
|
292
|
+
| 0.10
|
293
|
+
| -
|
294
|
+
|===
|
295
|
+
|
296
|
+
This cop checks for opportunities to use `assert_output`.
|
297
|
+
|
298
|
+
=== Examples
|
299
|
+
|
300
|
+
[source,ruby]
|
301
|
+
----
|
302
|
+
# bad
|
303
|
+
$stdout = StringIO.new
|
304
|
+
puts object.method
|
305
|
+
$stdout.rewind
|
306
|
+
assert_match expected, $stdout.read
|
307
|
+
|
308
|
+
# good
|
309
|
+
assert_output(expected) { puts object.method }
|
310
|
+
----
|
311
|
+
|
312
|
+
=== References
|
313
|
+
|
314
|
+
* https://minitest.rubystyle.guide/#assert-output
|
315
|
+
|
316
|
+
== Minitest/AssertPathExists
|
317
|
+
|
318
|
+
|===
|
319
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
320
|
+
|
321
|
+
| Pending
|
322
|
+
| Yes
|
323
|
+
| Yes
|
324
|
+
| 0.10
|
325
|
+
| -
|
326
|
+
|===
|
327
|
+
|
328
|
+
This cop enforces the test to use `assert_path_exists`
|
329
|
+
instead of using `assert(File.exist?(path))`.
|
330
|
+
|
331
|
+
=== Examples
|
332
|
+
|
333
|
+
[source,ruby]
|
334
|
+
----
|
335
|
+
# bad
|
336
|
+
assert(File.exist?(path))
|
337
|
+
assert(File.exist?(path), 'message')
|
338
|
+
|
339
|
+
# good
|
340
|
+
assert_path_exists(path)
|
341
|
+
assert_path_exists(path, 'message')
|
342
|
+
----
|
343
|
+
|
344
|
+
=== References
|
345
|
+
|
346
|
+
* https://minitest.rubystyle.guide/#assert-path-exists
|
347
|
+
|
348
|
+
== Minitest/AssertRespondTo
|
349
|
+
|
350
|
+
|===
|
351
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
352
|
+
|
353
|
+
| Enabled
|
354
|
+
| Yes
|
355
|
+
| Yes
|
356
|
+
| 0.3
|
357
|
+
| -
|
358
|
+
|===
|
359
|
+
|
360
|
+
This cop enforces the use of `assert_respond_to(object, :do_something)`
|
361
|
+
over `assert(object.respond_to?(:do_something))`.
|
362
|
+
|
363
|
+
=== Examples
|
364
|
+
|
365
|
+
[source,ruby]
|
366
|
+
----
|
367
|
+
# bad
|
368
|
+
assert(object.respond_to?(:do_something))
|
369
|
+
assert(object.respond_to?(:do_something), 'message')
|
370
|
+
assert(respond_to?(:do_something))
|
371
|
+
|
372
|
+
# good
|
373
|
+
assert_respond_to(object, :do_something)
|
374
|
+
assert_respond_to(object, :do_something, 'message')
|
375
|
+
assert_respond_to(self, :do_something)
|
376
|
+
----
|
377
|
+
|
378
|
+
=== References
|
379
|
+
|
380
|
+
* https://minitest.rubystyle.guide#assert-responds-to-method
|
381
|
+
|
382
|
+
== Minitest/AssertSilent
|
383
|
+
|
384
|
+
|===
|
385
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
386
|
+
|
387
|
+
| Pending
|
388
|
+
| Yes
|
389
|
+
| Yes
|
390
|
+
| 0.10
|
391
|
+
| -
|
392
|
+
|===
|
393
|
+
|
394
|
+
This cop enforces the test to use `assert_silent { ... }`
|
395
|
+
instead of using `assert_output('', '') { ... }`.
|
396
|
+
|
397
|
+
=== Examples
|
398
|
+
|
399
|
+
[source,ruby]
|
400
|
+
----
|
401
|
+
# bad
|
402
|
+
assert_output('', '') { puts object.do_something }
|
403
|
+
|
404
|
+
# good
|
405
|
+
assert_silent { puts object.do_something }
|
406
|
+
----
|
407
|
+
|
408
|
+
=== References
|
409
|
+
|
410
|
+
* https://github.com/rubocop-hq/minitest-style-guide#assert-silent
|
411
|
+
|
412
|
+
== Minitest/AssertTruthy
|
413
|
+
|
414
|
+
|===
|
415
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
416
|
+
|
417
|
+
| Enabled
|
418
|
+
| Yes
|
419
|
+
| Yes
|
420
|
+
| 0.2
|
421
|
+
| -
|
422
|
+
|===
|
423
|
+
|
424
|
+
This cop enforces the test to use `assert(actual)`
|
425
|
+
instead of using `assert_equal(true, actual)`.
|
426
|
+
|
427
|
+
=== Examples
|
428
|
+
|
429
|
+
[source,ruby]
|
430
|
+
----
|
431
|
+
# bad
|
432
|
+
assert_equal(true, actual)
|
433
|
+
assert_equal(true, actual, 'message')
|
434
|
+
|
435
|
+
# good
|
436
|
+
assert(actual)
|
437
|
+
assert(actual, 'message')
|
438
|
+
----
|
439
|
+
|
440
|
+
=== References
|
441
|
+
|
442
|
+
* https://minitest.rubystyle.guide#assert-truthy
|
443
|
+
|
444
|
+
== Minitest/AssertionInLifecycleHook
|
445
|
+
|
446
|
+
|===
|
447
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
448
|
+
|
449
|
+
| Pending
|
450
|
+
| Yes
|
451
|
+
| No
|
452
|
+
| 0.10
|
453
|
+
| -
|
454
|
+
|===
|
455
|
+
|
456
|
+
This cop checks for usage of assertions in lifecycle hooks.
|
457
|
+
|
458
|
+
=== Examples
|
459
|
+
|
460
|
+
[source,ruby]
|
461
|
+
----
|
462
|
+
# bad
|
463
|
+
class FooTest < Minitest::Test
|
464
|
+
def setup
|
465
|
+
assert_equal(foo, bar)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# good
|
470
|
+
class FooTest < Minitest::Test
|
471
|
+
def test_something
|
472
|
+
assert_equal(foo, bar)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
----
|
476
|
+
|
477
|
+
== Minitest/GlobalExpectations
|
478
|
+
|
479
|
+
|===
|
480
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
481
|
+
|
482
|
+
| Enabled
|
483
|
+
| Yes
|
484
|
+
| Yes
|
485
|
+
| 0.7
|
486
|
+
| -
|
487
|
+
|===
|
488
|
+
|
489
|
+
This cop checks for deprecated global expectations
|
490
|
+
and autocorrects them to use expect format.
|
491
|
+
|
492
|
+
=== Examples
|
493
|
+
|
494
|
+
[source,ruby]
|
495
|
+
----
|
496
|
+
# bad
|
497
|
+
musts.must_equal expected_musts
|
498
|
+
wonts.wont_match expected_wonts
|
499
|
+
musts.must_raise TypeError
|
500
|
+
|
501
|
+
# good
|
502
|
+
_(musts).must_equal expected_musts
|
503
|
+
_(wonts).wont_match expected_wonts
|
504
|
+
_ { musts }.must_raise TypeError
|
505
|
+
----
|
506
|
+
|
507
|
+
=== References
|
508
|
+
|
509
|
+
* https://minitest.rubystyle.guide#global-expectations
|
510
|
+
|
511
|
+
== Minitest/LiteralAsActualArgument
|
512
|
+
|
513
|
+
|===
|
514
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
515
|
+
|
516
|
+
| Pending
|
517
|
+
| Yes
|
518
|
+
| Yes
|
519
|
+
| 0.10
|
520
|
+
| -
|
521
|
+
|===
|
522
|
+
|
523
|
+
This cop enforces correct order of expected and
|
524
|
+
actual arguments for `assert_equal`.
|
525
|
+
|
526
|
+
=== Examples
|
527
|
+
|
528
|
+
[source,ruby]
|
529
|
+
----
|
530
|
+
# bad
|
531
|
+
assert_equal foo, 2
|
532
|
+
assert_equal foo, [1, 2]
|
533
|
+
assert_equal foo, [1, 2], 'message'
|
534
|
+
|
535
|
+
# good
|
536
|
+
assert_equal 2, foo
|
537
|
+
assert_equal [1, 2], foo
|
538
|
+
assert_equal [1, 2], foo, 'message'
|
539
|
+
----
|
540
|
+
|
541
|
+
=== References
|
542
|
+
|
543
|
+
* https://minitest.rubystyle.guide/#assert-equal-arguments-order
|
544
|
+
|
545
|
+
== Minitest/MultipleAssertions
|
546
|
+
|
547
|
+
|===
|
548
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
549
|
+
|
550
|
+
| Pending
|
551
|
+
| Yes
|
552
|
+
| No
|
553
|
+
| 0.10
|
554
|
+
| -
|
555
|
+
|===
|
556
|
+
|
557
|
+
This cop checks if test cases contain too many assertion calls.
|
558
|
+
The maximum allowed assertion calls is configurable.
|
559
|
+
|
560
|
+
=== Examples
|
561
|
+
|
562
|
+
==== Max: 1
|
563
|
+
|
564
|
+
[source,ruby]
|
565
|
+
----
|
566
|
+
# bad
|
567
|
+
class FooTest < Minitest::Test
|
568
|
+
def test_asserts_twice
|
569
|
+
assert_equal(42, do_something)
|
570
|
+
assert_empty(array)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
# good
|
575
|
+
class FooTest < Minitest::Test
|
576
|
+
def test_asserts_once
|
577
|
+
assert_equal(42, do_something)
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_another_asserts_once
|
581
|
+
assert_empty(array)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
----
|
585
|
+
|
586
|
+
=== Configurable attributes
|
587
|
+
|
588
|
+
|===
|
589
|
+
| Name | Default value | Configurable values
|
590
|
+
|
591
|
+
| Max
|
592
|
+
| `3`
|
593
|
+
| Integer
|
594
|
+
|===
|
595
|
+
|
596
|
+
== Minitest/RefuteEmpty
|
597
|
+
|
598
|
+
|===
|
599
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
600
|
+
|
601
|
+
| Enabled
|
602
|
+
| Yes
|
603
|
+
| Yes
|
604
|
+
| 0.3
|
605
|
+
| -
|
606
|
+
|===
|
607
|
+
|
608
|
+
This cop enforces to use `refute_empty` instead of
|
609
|
+
using `refute(object.empty?)`.
|
610
|
+
|
611
|
+
=== Examples
|
612
|
+
|
613
|
+
[source,ruby]
|
614
|
+
----
|
615
|
+
# bad
|
616
|
+
refute(object.empty?)
|
617
|
+
refute(object.empty?, 'message')
|
618
|
+
|
619
|
+
# good
|
620
|
+
refute_empty(object)
|
621
|
+
refute_empty(object, 'message')
|
622
|
+
----
|
623
|
+
|
624
|
+
=== References
|
625
|
+
|
626
|
+
* https://minitest.rubystyle.guide#refute-empty
|
627
|
+
|
628
|
+
== Minitest/RefuteEqual
|
629
|
+
|
630
|
+
|===
|
631
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
632
|
+
|
633
|
+
| Enabled
|
634
|
+
| Yes
|
635
|
+
| Yes
|
636
|
+
| 0.3
|
637
|
+
| -
|
638
|
+
|===
|
639
|
+
|
640
|
+
This cop enforces the use of `refute_equal(expected, object)`
|
641
|
+
over `assert_equal(expected != actual)` or `assert(! expected == actual)`.
|
642
|
+
|
643
|
+
=== Examples
|
644
|
+
|
645
|
+
[source,ruby]
|
646
|
+
----
|
647
|
+
# bad
|
648
|
+
assert("rubocop-minitest" != actual)
|
649
|
+
assert(! "rubocop-minitest" == actual)
|
650
|
+
|
651
|
+
# good
|
652
|
+
refute_equal("rubocop-minitest", actual)
|
653
|
+
----
|
654
|
+
|
655
|
+
=== References
|
656
|
+
|
657
|
+
* https://minitest.rubystyle.guide#refute-equal
|
658
|
+
|
659
|
+
== Minitest/RefuteFalse
|
660
|
+
|
661
|
+
|===
|
662
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
663
|
+
|
664
|
+
| Enabled
|
665
|
+
| Yes
|
666
|
+
| Yes
|
667
|
+
| 0.3
|
668
|
+
| -
|
669
|
+
|===
|
670
|
+
|
671
|
+
This cop enforces the use of `refute(object)`
|
672
|
+
over `assert_equal(false, object)`.
|
673
|
+
|
674
|
+
=== Examples
|
675
|
+
|
676
|
+
[source,ruby]
|
677
|
+
----
|
678
|
+
# bad
|
679
|
+
assert_equal(false, actual)
|
680
|
+
assert_equal(false, actual, 'message')
|
681
|
+
|
682
|
+
assert(!test)
|
683
|
+
assert(!test, 'message')
|
684
|
+
|
685
|
+
# good
|
686
|
+
refute(actual)
|
687
|
+
refute(actual, 'message')
|
688
|
+
----
|
689
|
+
|
690
|
+
=== References
|
691
|
+
|
692
|
+
* https://minitest.rubystyle.guide#refute-false
|
693
|
+
|
694
|
+
== Minitest/RefuteInDelta
|
695
|
+
|
696
|
+
|===
|
697
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
698
|
+
|
699
|
+
| Pending
|
700
|
+
| Yes
|
701
|
+
| Yes
|
702
|
+
| 0.10
|
703
|
+
| -
|
704
|
+
|===
|
705
|
+
|
706
|
+
This cop enforces the test to use `refute_in_delta`
|
707
|
+
instead of using `refute_equal` to compare floats.
|
708
|
+
|
709
|
+
=== Examples
|
710
|
+
|
711
|
+
[source,ruby]
|
712
|
+
----
|
713
|
+
# bad
|
714
|
+
refute_equal(0.2, actual)
|
715
|
+
refute_equal(0.2, actual, 'message')
|
716
|
+
|
717
|
+
# good
|
718
|
+
refute_in_delta(0.2, actual)
|
719
|
+
refute_in_delta(0.2, actual, 0.001, 'message')
|
720
|
+
----
|
721
|
+
|
722
|
+
=== References
|
723
|
+
|
724
|
+
* https://minitest.rubystyle.guide/#refute-in-delta
|
725
|
+
|
726
|
+
== Minitest/RefuteIncludes
|
727
|
+
|
728
|
+
|===
|
729
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
730
|
+
|
731
|
+
| Enabled
|
732
|
+
| Yes
|
733
|
+
| Yes
|
734
|
+
| 0.3
|
735
|
+
| -
|
736
|
+
|===
|
737
|
+
|
738
|
+
This cop enforces the test to use `refute_includes`
|
739
|
+
instead of using `refute(collection.include?(object))`.
|
740
|
+
|
741
|
+
=== Examples
|
742
|
+
|
743
|
+
[source,ruby]
|
744
|
+
----
|
745
|
+
# bad
|
746
|
+
refute(collection.include?(object))
|
747
|
+
refute(collection.include?(object), 'message')
|
748
|
+
|
749
|
+
# good
|
750
|
+
refute_includes(collection, object)
|
751
|
+
refute_includes(collection, object, 'message')
|
752
|
+
----
|
753
|
+
|
754
|
+
=== References
|
755
|
+
|
756
|
+
* https://minitest.rubystyle.guide#refute-includes
|
757
|
+
|
758
|
+
== Minitest/RefuteInstanceOf
|
759
|
+
|
760
|
+
|===
|
761
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
762
|
+
|
763
|
+
| Enabled
|
764
|
+
| Yes
|
765
|
+
| Yes
|
766
|
+
| 0.4
|
767
|
+
| -
|
768
|
+
|===
|
769
|
+
|
770
|
+
This cop enforces the use of `refute_instance_of(Class, object)`
|
771
|
+
over `refute(object.instance_of?(Class))`.
|
772
|
+
|
773
|
+
=== Examples
|
774
|
+
|
775
|
+
[source,ruby]
|
776
|
+
----
|
777
|
+
# bad
|
778
|
+
refute(object.instance_of?(Class))
|
779
|
+
refute(object.instance_of?(Class), 'message')
|
780
|
+
|
781
|
+
# good
|
782
|
+
refute_instance_of(Class, object)
|
783
|
+
refute_instance_of(Class, object, 'message')
|
784
|
+
----
|
785
|
+
|
786
|
+
=== References
|
787
|
+
|
788
|
+
* https://minitest.rubystyle.guide#refute-instance-of
|
789
|
+
|
790
|
+
== Minitest/RefuteKindOf
|
791
|
+
|
792
|
+
|===
|
793
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
794
|
+
|
795
|
+
| Pending
|
796
|
+
| Yes
|
797
|
+
| Yes
|
798
|
+
| 0.10
|
799
|
+
| -
|
800
|
+
|===
|
801
|
+
|
802
|
+
This cop enforces the use of `refute_kind_of(Class, object)`
|
803
|
+
over `refute(object.kind_of?(Class))`.
|
804
|
+
|
805
|
+
=== Examples
|
806
|
+
|
807
|
+
[source,ruby]
|
808
|
+
----
|
809
|
+
# bad
|
810
|
+
refute(object.kind_of?(Class))
|
811
|
+
refute(object.kind_of?(Class), 'message')
|
812
|
+
|
813
|
+
# good
|
814
|
+
refute_kind_of(Class, object)
|
815
|
+
refute_kind_of(Class, object, 'message')
|
816
|
+
----
|
817
|
+
|
818
|
+
=== References
|
819
|
+
|
820
|
+
* https://github.com/rubocop-hq/minitest-style-guide#refute-kind-of
|
821
|
+
|
822
|
+
== Minitest/RefuteMatch
|
823
|
+
|
824
|
+
|===
|
825
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
826
|
+
|
827
|
+
| Enabled
|
828
|
+
| Yes
|
829
|
+
| Yes
|
830
|
+
| 0.6
|
831
|
+
| -
|
832
|
+
|===
|
833
|
+
|
834
|
+
This cop enforces the test to use `refute_match`
|
835
|
+
instead of using `refute(matcher.match(string))`.
|
836
|
+
|
837
|
+
=== Examples
|
838
|
+
|
839
|
+
[source,ruby]
|
840
|
+
----
|
841
|
+
# bad
|
842
|
+
refute(matcher.match(string))
|
843
|
+
refute(matcher.match(string), 'message')
|
844
|
+
|
845
|
+
# good
|
846
|
+
refute_match(matcher, string)
|
847
|
+
refute_match(matcher, string, 'message')
|
848
|
+
----
|
849
|
+
|
850
|
+
=== References
|
851
|
+
|
852
|
+
* https://minitest.rubystyle.guide#refute-match
|
853
|
+
|
854
|
+
== Minitest/RefuteNil
|
855
|
+
|
856
|
+
|===
|
857
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
858
|
+
|
859
|
+
| Enabled
|
860
|
+
| Yes
|
861
|
+
| Yes
|
862
|
+
| 0.2
|
863
|
+
| -
|
864
|
+
|===
|
865
|
+
|
866
|
+
This cop enforces the test to use `refute_nil`
|
867
|
+
instead of using `refute_equal(nil, something)`.
|
868
|
+
|
869
|
+
=== Examples
|
870
|
+
|
871
|
+
[source,ruby]
|
872
|
+
----
|
873
|
+
# bad
|
874
|
+
refute_equal(nil, actual)
|
875
|
+
refute_equal(nil, actual, 'message')
|
876
|
+
|
877
|
+
# good
|
878
|
+
refute_nil(actual)
|
879
|
+
refute_nil(actual, 'message')
|
880
|
+
----
|
881
|
+
|
882
|
+
=== References
|
883
|
+
|
884
|
+
* https://minitest.rubystyle.guide#refute-nil
|
885
|
+
|
886
|
+
== Minitest/RefutePathExists
|
887
|
+
|
888
|
+
|===
|
889
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
890
|
+
|
891
|
+
| Pending
|
892
|
+
| Yes
|
893
|
+
| Yes
|
894
|
+
| 0.10
|
895
|
+
| -
|
896
|
+
|===
|
897
|
+
|
898
|
+
This cop enforces the test to use `refute_path_exists`
|
899
|
+
instead of using `refute(File.exist?(path))`.
|
900
|
+
|
901
|
+
=== Examples
|
902
|
+
|
903
|
+
[source,ruby]
|
904
|
+
----
|
905
|
+
# bad
|
906
|
+
refute(File.exist?(path))
|
907
|
+
refute(File.exist?(path), 'message')
|
908
|
+
|
909
|
+
# good
|
910
|
+
refute_path_exists(path)
|
911
|
+
refute_path_exists(path, 'message')
|
912
|
+
----
|
913
|
+
|
914
|
+
=== References
|
915
|
+
|
916
|
+
* https://minitest.rubystyle.guide/#refute-path-exists
|
917
|
+
|
918
|
+
== Minitest/RefuteRespondTo
|
919
|
+
|
920
|
+
|===
|
921
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
922
|
+
|
923
|
+
| Enabled
|
924
|
+
| Yes
|
925
|
+
| Yes
|
926
|
+
| 0.4
|
927
|
+
| -
|
928
|
+
|===
|
929
|
+
|
930
|
+
This cop enforces the test to use `refute_respond_to(object, :do_something)`
|
931
|
+
over `refute(object.respond_to?(:do_something))`.
|
932
|
+
|
933
|
+
=== Examples
|
934
|
+
|
935
|
+
[source,ruby]
|
936
|
+
----
|
937
|
+
# bad
|
938
|
+
refute(object.respond_to?(:do_something))
|
939
|
+
refute(object.respond_to?(:do_something), 'message')
|
940
|
+
refute(respond_to?(:do_something))
|
941
|
+
|
942
|
+
# good
|
943
|
+
refute_respond_to(object, :do_something)
|
944
|
+
refute_respond_to(object, :do_something, 'message')
|
945
|
+
refute_respond_to(self, :do_something)
|
946
|
+
----
|
947
|
+
|
948
|
+
=== References
|
949
|
+
|
950
|
+
* https://minitest.rubystyle.guide#refute-respond-to
|
951
|
+
|
952
|
+
== Minitest/TestMethodName
|
953
|
+
|
954
|
+
|===
|
955
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
956
|
+
|
957
|
+
| Pending
|
958
|
+
| Yes
|
959
|
+
| Yes
|
960
|
+
| 0.10
|
961
|
+
| -
|
962
|
+
|===
|
963
|
+
|
964
|
+
This cop enforces that test method names start with `test_` prefix.
|
965
|
+
|
966
|
+
=== Examples
|
967
|
+
|
968
|
+
[source,ruby]
|
969
|
+
----
|
970
|
+
# bad
|
971
|
+
class FooTest < Minitest::Test
|
972
|
+
def does_something
|
973
|
+
assert_equal 42, do_something
|
974
|
+
end
|
975
|
+
end
|
976
|
+
|
977
|
+
# good
|
978
|
+
class FooTest < Minitest::Test
|
979
|
+
def test_does_something
|
980
|
+
assert_equal 42, do_something
|
981
|
+
end
|
982
|
+
end
|
983
|
+
----
|
984
|
+
|
985
|
+
== Minitest/UnspecifiedException
|
986
|
+
|
987
|
+
|===
|
988
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
989
|
+
|
990
|
+
| Pending
|
991
|
+
| Yes
|
992
|
+
| No
|
993
|
+
| 0.10
|
994
|
+
| -
|
995
|
+
|===
|
996
|
+
|
997
|
+
This cop checks for a specified error in `assert_raises`.
|
998
|
+
|
999
|
+
=== Examples
|
1000
|
+
|
1001
|
+
[source,ruby]
|
1002
|
+
----
|
1003
|
+
# bad
|
1004
|
+
assert_raises { raise FooException }
|
1005
|
+
assert_raises('This should have raised') { raise FooException }
|
1006
|
+
|
1007
|
+
# good
|
1008
|
+
assert_raises(FooException) { raise FooException }
|
1009
|
+
assert_raises(FooException, 'This should have raised') { raise FooException }
|
1010
|
+
----
|
1011
|
+
|
1012
|
+
=== References
|
1013
|
+
|
1014
|
+
* https://minitest.rubystyle.guide#unspecified-exception
|