rubocop-minitest 0.19.1 → 0.20.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/.github/ISSUE_TEMPLATE/feature_request.md +1 -1
- data/.github/workflows/spell_checking.yml +1 -1
- data/.rubocop.yml +6 -1
- data/CHANGELOG.md +17 -3
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -1
- data/config/default.yml +6 -0
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +1 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +114 -43
- data/lib/rubocop/cop/minitest/assert_empty.rb +1 -2
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +1 -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 +1 -1
- data/lib/rubocop/cop/minitest/assert_output.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +1 -2
- data/lib/rubocop/cop/minitest/assert_predicate.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_respond_to.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_silent.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_truthy.rb +1 -2
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +1 -1
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +1 -1
- data/lib/rubocop/cop/minitest/duplicate_test_run.rb +1 -1
- data/lib/rubocop/cop/minitest/global_expectations.rb +1 -1
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +1 -1
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +1 -1
- data/lib/rubocop/cop/minitest/no_assertions.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_empty.rb +1 -2
- data/lib/rubocop/cop/minitest/refute_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_false.rb +1 -2
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +1 -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 +1 -1
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +1 -2
- data/lib/rubocop/cop/minitest/refute_predicate.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_respond_to.rb +1 -1
- data/lib/rubocop/cop/minitest/skip_ensure.rb +95 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +1 -1
- data/lib/rubocop/cop/minitest/unreachable_assertion.rb +1 -1
- data/lib/rubocop/cop/minitest/unspecified_exception.rb +1 -1
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +2 -2
- data/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb +6 -2
- data/lib/rubocop/minitest/assert_offense.rb +3 -3
- data/lib/rubocop/minitest/version.rb +1 -1
- data/relnotes/v0.12.0.md +1 -1
- data/relnotes/v0.15.2.md +1 -1
- data/relnotes/v0.20.0.md +13 -0
- data/relnotes/v0.9.0.md +1 -1
- data/rubocop-minitest.gemspec +1 -1
- metadata +7 -5
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
7
|
-
# instead of using `assert(File.exist?(path))`.
|
6
|
+
# Enforces the test to use `assert_path_exists` instead of using `assert(File.exist?(path))`.
|
8
7
|
#
|
9
8
|
# @example
|
10
9
|
# # bad
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
7
|
-
# instead of using `assert_equal(true, actual)`.
|
6
|
+
# Enforces the test to use `assert(actual)` instead of using `assert_equal(true, actual)`.
|
8
7
|
#
|
9
8
|
# @example
|
10
9
|
# # bad
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# it will also inherit its methods causing Minitest to run the parent's tests methods twice.
|
8
8
|
#
|
9
9
|
# This cop detects when there are two tests classes, one inherits from the other, and both have tests methods.
|
10
|
-
# This cop will add an
|
10
|
+
# This cop will add an offense to the Child class in such a case.
|
11
11
|
#
|
12
12
|
# @example
|
13
13
|
# # bad
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
6
|
+
# Enforces the test to use `refute_nil` instead of using
|
7
7
|
# `refute_equal(nil, something)`, `refute(something.nil?)`, or `refute_predicate(something, :nil?)`.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
7
|
-
# instead of using `refute(File.exist?(path))`.
|
6
|
+
# Enforces the test to use `refute_path_exists` instead of using `refute(File.exist?(path))`.
|
8
7
|
#
|
9
8
|
# @example
|
10
9
|
# # bad
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
6
|
+
# Enforces the test to use `refute_respond_to(object, :do_something)`
|
7
7
|
# over `refute(object.respond_to?(:do_something))`.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# Checks that `ensure` call even if `skip`. It is unexpected that `ensure` will be called when skipping test.
|
7
|
+
# If conditional `skip` is used, it checks that `ensure` is also called conditionally.
|
8
|
+
#
|
9
|
+
# On the other hand, it accepts `skip` used in `rescue` because `ensure` may be teardown process to `begin`
|
10
|
+
# setup process.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# def test_skip
|
16
|
+
# skip 'This test is skipped.'
|
17
|
+
#
|
18
|
+
# assert 'foo'.present?
|
19
|
+
# ensure
|
20
|
+
# do_something
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# def test_conditional_skip
|
25
|
+
# skip 'This test is skipped.' if condition
|
26
|
+
#
|
27
|
+
# assert do_something
|
28
|
+
# ensure
|
29
|
+
# do_teardown
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# def test_skip
|
34
|
+
# skip 'This test is skipped.'
|
35
|
+
#
|
36
|
+
# begin
|
37
|
+
# assert 'foo'.present?
|
38
|
+
# ensure
|
39
|
+
# do_something
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # good
|
44
|
+
# def test_conditional_skip
|
45
|
+
# skip 'This test is skipped.' if condition
|
46
|
+
#
|
47
|
+
# assert do_something
|
48
|
+
# ensure
|
49
|
+
# if condition
|
50
|
+
# do_teardown
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# # good
|
55
|
+
# def test_skip_is_used_in_rescue
|
56
|
+
# do_setup
|
57
|
+
# assert do_something
|
58
|
+
# rescue
|
59
|
+
# skip 'This test is skipped.'
|
60
|
+
# ensure
|
61
|
+
# do_teardown
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
class SkipEnsure < Base
|
65
|
+
MSG = '`ensure` is called even though the test is skipped.'
|
66
|
+
|
67
|
+
def on_ensure(node)
|
68
|
+
skip = find_skip(node)
|
69
|
+
|
70
|
+
return if skip.nil? || use_skip_in_rescue?(skip) || valid_conditional_skip?(skip, node)
|
71
|
+
|
72
|
+
add_offense(node.loc.keyword)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def find_skip(node)
|
78
|
+
node.node_parts.first.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def use_skip_in_rescue?(skip_method)
|
82
|
+
skip_method.ancestors.detect(&:rescue_type?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def valid_conditional_skip?(skip_method, ensure_node)
|
86
|
+
if_node = skip_method.ancestors.detect(&:if_type?)
|
87
|
+
return false unless ensure_node.body.if_type?
|
88
|
+
|
89
|
+
match_keyword = ensure_node.body.if? ? if_node.if? : if_node.unless?
|
90
|
+
match_keyword && ensure_node.body.condition == if_node.condition
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
#
|
6
|
+
# Enforces that test method names start with `test_` prefix.
|
7
7
|
# It aims to prevent tests that aren't executed by forgetting to start test method name with `test_`.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -40,6 +40,7 @@ require_relative 'minitest/refute_instance_of'
|
|
40
40
|
require_relative 'minitest/refute_path_exists'
|
41
41
|
require_relative 'minitest/refute_predicate'
|
42
42
|
require_relative 'minitest/refute_respond_to'
|
43
|
+
require_relative 'minitest/skip_ensure'
|
43
44
|
require_relative 'minitest/test_method_name'
|
44
45
|
require_relative 'minitest/unreachable_assertion'
|
45
46
|
require_relative 'minitest/unspecified_exception'
|
@@ -16,10 +16,10 @@ module RuboCop
|
|
16
16
|
# @param assertion_method [Symbol] Assertion method like `assert` or `refute`.
|
17
17
|
# @param target_method [Symbol] Method name offensed by assertion method arguments.
|
18
18
|
# @param preferred_method [Symbol] An optional param. Custom method name replaced by
|
19
|
-
#
|
19
|
+
# autocorrection. The preferred method name that connects
|
20
20
|
# `assertion_method` and `target_method` with `_` is
|
21
21
|
# the default name.
|
22
|
-
# @param inverse [Boolean] An optional param. Order of arguments replaced by
|
22
|
+
# @param inverse [Boolean] An optional param. Order of arguments replaced by autocorrection.
|
23
23
|
#
|
24
24
|
def define_rule(assertion_method, target_method:, preferred_method: nil, inverse: false)
|
25
25
|
preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}" if preferred_method.nil?
|
@@ -10,8 +10,12 @@ module RuboCop
|
|
10
10
|
|
11
11
|
def on_send(node)
|
12
12
|
return unless (arguments = peel_redundant_parentheses_from(node.arguments))
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
first_argument = arguments.first
|
15
|
+
|
16
|
+
return if first_argument.block_type? || first_argument.numblock_type?
|
17
|
+
return unless first_argument.respond_to?(:predicate_method?) && first_argument.predicate_method?
|
18
|
+
return unless first_argument.arguments.count.zero?
|
15
19
|
|
16
20
|
add_offense(node, message: offense_message(arguments)) do |corrector|
|
17
21
|
autocorrect(corrector, node, arguments)
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
# that there were no offenses. The `assert_offense` method has
|
56
56
|
# to do more work by parsing out lines that contain carets.
|
57
57
|
#
|
58
|
-
# If the code produces an offense that could not be
|
58
|
+
# If the code produces an offense that could not be autocorrected, you can
|
59
59
|
# use `assert_no_corrections` after `assert_offense`.
|
60
60
|
#
|
61
61
|
# @example `assert_offense` and `assert_no_corrections`
|
@@ -93,7 +93,7 @@ module RuboCop
|
|
93
93
|
def assert_offense(source, file = nil)
|
94
94
|
setup_assertion
|
95
95
|
|
96
|
-
@cop.instance_variable_get(:@options)[:
|
96
|
+
@cop.instance_variable_get(:@options)[:autocorrect] = true
|
97
97
|
|
98
98
|
expected_annotations = RuboCop::RSpec::ExpectOffense::AnnotatedSource.parse(source)
|
99
99
|
if expected_annotations.plain_source == source
|
@@ -176,7 +176,7 @@ module RuboCop
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def ruby_version
|
179
|
-
2.
|
179
|
+
2.6
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
data/relnotes/v0.12.0.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### Changes
|
6
6
|
|
7
|
-
* [#129](https://github.com/rubocop/rubocop-minitest/pull/129): Drop Ruby 2.4 support. ([@koic][])
|
7
|
+
* [#129](https://github.com/rubocop/rubocop-minitest/pull/129): **(Compatibility)** Drop Ruby 2.4 support. ([@koic][])
|
8
8
|
|
9
9
|
[@ghiculescu]: https://github.com/ghiculescu
|
10
10
|
[@koic]: https://github.com/koic
|
data/relnotes/v0.15.2.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### Bug fixes
|
2
2
|
|
3
|
-
* [#145](https://github.com/rubocop/rubocop-minitest/pull/145): Mark `Minitest/AssertEmptyLiteral` as safe
|
3
|
+
* [#145](https://github.com/rubocop/rubocop-minitest/pull/145): Mark `Minitest/AssertEmptyLiteral` as safe autocorrection. ([@koic][])
|
4
4
|
|
5
5
|
[@koic]: https://github.com/koic
|
data/relnotes/v0.20.0.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#169](https://github.com/rubocop/rubocop-minitest/issues/169): Add new `Minitest/SkipEnsure` cop. ([@koic][])
|
4
|
+
|
5
|
+
### Bug fixes
|
6
|
+
|
7
|
+
* [#172](https://github.com/rubocop/rubocop-minitest/issues/172): Fix a false positive for `Minitest/AssertPredicate` and `Minitest/RefutePredicate` when using numbered parameters. ([@koic][])
|
8
|
+
|
9
|
+
### Changes
|
10
|
+
|
11
|
+
* [#168](https://github.com/rubocop/rubocop-minitest/pull/168): **(Compatibility)** Drop Ruby 2.5 support. ([@koic][])
|
12
|
+
|
13
|
+
[@koic]: https://github.com/koic
|
data/relnotes/v0.9.0.md
CHANGED
@@ -5,6 +5,6 @@
|
|
5
5
|
### Changes
|
6
6
|
|
7
7
|
* [#73](https://github.com/rubocop/rubocop-minitest/issues/73): The Minitest department works on file names end with `_test.rb` by default. ([@koic][])
|
8
|
-
* [#77](https://github.com/rubocop/rubocop-minitest/pull/77): **(
|
8
|
+
* [#77](https://github.com/rubocop/rubocop-minitest/pull/77): **(Compatibility)** Drop support for Ruby 2.3. ([@koic][])
|
9
9
|
|
10
10
|
[@koic]: https://github.com/koic
|
data/rubocop-minitest.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
DESCRIPTION
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
|
-
spec.required_ruby_version = '>= 2.
|
19
|
+
spec.required_ruby_version = '>= 2.6.0'
|
20
20
|
spec.metadata = {
|
21
21
|
'homepage_uri' => 'https://docs.rubocop.org/rubocop-minitest/',
|
22
22
|
'changelog_uri' => 'https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md',
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/rubocop/cop/minitest/refute_path_exists.rb
|
126
126
|
- lib/rubocop/cop/minitest/refute_predicate.rb
|
127
127
|
- lib/rubocop/cop/minitest/refute_respond_to.rb
|
128
|
+
- lib/rubocop/cop/minitest/skip_ensure.rb
|
128
129
|
- lib/rubocop/cop/minitest/test_method_name.rb
|
129
130
|
- lib/rubocop/cop/minitest/unreachable_assertion.rb
|
130
131
|
- lib/rubocop/cop/minitest/unspecified_exception.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- relnotes/v0.19.1.md
|
166
167
|
- relnotes/v0.2.0.md
|
167
168
|
- relnotes/v0.2.1.md
|
169
|
+
- relnotes/v0.20.0.md
|
168
170
|
- relnotes/v0.3.0.md
|
169
171
|
- relnotes/v0.4.0.md
|
170
172
|
- relnotes/v0.4.1.md
|
@@ -189,7 +191,7 @@ metadata:
|
|
189
191
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
190
192
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
191
193
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
192
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
194
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.20
|
193
195
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
194
196
|
rubygems_mfa_required: 'true'
|
195
197
|
post_install_message:
|
@@ -200,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
202
|
requirements:
|
201
203
|
- - ">="
|
202
204
|
- !ruby/object:Gem::Version
|
203
|
-
version: 2.
|
205
|
+
version: 2.6.0
|
204
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
207
|
requirements:
|
206
208
|
- - ">="
|
207
209
|
- !ruby/object:Gem::Version
|
208
210
|
version: '0'
|
209
211
|
requirements: []
|
210
|
-
rubygems_version: 3.3.
|
212
|
+
rubygems_version: 3.3.7
|
211
213
|
signing_key:
|
212
214
|
specification_version: 4
|
213
215
|
summary: Automatic Minitest code style checking tool.
|