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
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop checks for `assert_raises` has an assertion method at
|
7
|
+
# the bottom of block because the assertion will be never reached.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# assert_raises FooError do
|
13
|
+
# obj.occur_error
|
14
|
+
# assert_equal('foo', obj.bar) # Never asserted.
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# assert_raises FooError do
|
19
|
+
# obj.occur_error
|
20
|
+
# end
|
21
|
+
# assert_equal('foo', obj.bar)
|
22
|
+
#
|
23
|
+
class UnreachableAssertion < Base
|
24
|
+
include MinitestExplorationHelpers
|
25
|
+
|
26
|
+
MSG = 'Unreachable `%<assertion_method>s` detected.'
|
27
|
+
|
28
|
+
def on_block(node)
|
29
|
+
return unless node.method?(:assert_raises) && (body = node.body)
|
30
|
+
|
31
|
+
last_node = body.begin_type? ? body.children.last : body
|
32
|
+
return unless last_node.send_type?
|
33
|
+
|
34
|
+
method_name = last_node.method_name
|
35
|
+
return unless assertion_method?(method_name)
|
36
|
+
|
37
|
+
add_offense(last_node, message: format(MSG, assertion_method: method_name))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# assert_raises(FooException) { raise FooException }
|
15
15
|
# assert_raises(FooException, 'This should have raised') { raise FooException }
|
16
16
|
#
|
17
|
-
class UnspecifiedException <
|
17
|
+
class UnspecifiedException < Base
|
18
18
|
MSG = 'Specify the exception being captured.'
|
19
19
|
|
20
20
|
def on_block(block_node)
|
@@ -23,6 +23,7 @@ require_relative 'minitest/assert_truthy'
|
|
23
23
|
require_relative 'minitest/global_expectations'
|
24
24
|
require_relative 'minitest/literal_as_actual_argument'
|
25
25
|
require_relative 'minitest/multiple_assertions'
|
26
|
+
require_relative 'minitest/no_assertions'
|
26
27
|
require_relative 'minitest/refute_empty'
|
27
28
|
require_relative 'minitest/refute_false'
|
28
29
|
require_relative 'minitest/refute_equal'
|
@@ -35,4 +36,5 @@ require_relative 'minitest/refute_instance_of'
|
|
35
36
|
require_relative 'minitest/refute_path_exists'
|
36
37
|
require_relative 'minitest/refute_respond_to'
|
37
38
|
require_relative 'minitest/test_method_name'
|
39
|
+
require_relative 'minitest/unreachable_assertion'
|
38
40
|
require_relative 'minitest/unspecified_exception'
|
@@ -9,24 +9,14 @@ module RuboCop
|
|
9
9
|
def on_send(node)
|
10
10
|
equal_floats_call(node) do |expected, actual, message|
|
11
11
|
message = message.first
|
12
|
+
good_method = build_good_method(expected, actual, message)
|
12
13
|
|
13
14
|
if expected.float_type? || actual.float_type?
|
14
|
-
message = format(MSG,
|
15
|
-
good_method: build_good_method(expected, actual, message),
|
16
|
-
bad_method: node.source)
|
15
|
+
message = format(MSG, good_method: good_method, bad_method: node.source)
|
17
16
|
|
18
|
-
add_offense(node, message: message)
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def autocorrect(node)
|
24
|
-
equal_floats_call(node) do |expected, actual, message|
|
25
|
-
message = message.first
|
26
|
-
replacement = build_good_method(expected, actual, message)
|
27
|
-
|
28
|
-
lambda do |corrector|
|
29
|
-
corrector.replace(node, replacement)
|
17
|
+
add_offense(node, message: message) do |corrector|
|
18
|
+
corrector.replace(node, good_method)
|
19
|
+
end
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
@@ -26,6 +26,7 @@ module RuboCop
|
|
26
26
|
|
27
27
|
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
28
28
|
include ArgumentRangeHelper
|
29
|
+
extend AutoCorrector
|
29
30
|
|
30
31
|
MSG = 'Prefer using `#{preferred_method}(%<new_arguments>s)` over ' \
|
31
32
|
'`#{assertion_method}(%<original_arguments>s)`.'
|
@@ -36,23 +37,21 @@ module RuboCop
|
|
36
37
|
return unless (arguments = peel_redundant_parentheses_from(node.arguments))
|
37
38
|
return unless arguments.first.respond_to?(:method?) && arguments.first.method?(:#{target_method})
|
38
39
|
|
39
|
-
add_offense(node, message: offense_message(arguments))
|
40
|
+
add_offense(node, message: offense_message(arguments)) do |corrector|
|
41
|
+
autocorrect(corrector, node, arguments)
|
42
|
+
end
|
40
43
|
end
|
41
44
|
|
42
|
-
def autocorrect(node)
|
43
|
-
|
44
|
-
corrector.replace(node.loc.selector, '#{preferred_method}')
|
45
|
-
|
46
|
-
arguments = peel_redundant_parentheses_from(node.arguments)
|
45
|
+
def autocorrect(corrector, node, arguments)
|
46
|
+
corrector.replace(node.loc.selector, '#{preferred_method}')
|
47
47
|
|
48
|
-
|
48
|
+
new_arguments = new_arguments(arguments).join(', ')
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
corrector.replace(first_argument_range(node), new_arguments)
|
50
|
+
if enclosed_in_redundant_parentheses?(node)
|
51
|
+
new_arguments = '(' + new_arguments + ')'
|
55
52
|
end
|
53
|
+
|
54
|
+
corrector.replace(first_argument_range(node), new_arguments)
|
56
55
|
end
|
57
56
|
|
58
57
|
private
|
@@ -19,6 +19,8 @@ module RuboCop
|
|
19
19
|
refute_respond_to refute_same
|
20
20
|
].freeze
|
21
21
|
|
22
|
+
FLUNK = 'flunk'
|
23
|
+
|
22
24
|
LIFECYCLE_HOOK_METHODS = %i[
|
23
25
|
before_setup
|
24
26
|
setup
|
@@ -42,8 +44,13 @@ module RuboCop
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_cases(class_node)
|
45
|
-
class_def_nodes(class_node)
|
46
|
-
|
47
|
+
test_cases = class_def_nodes(class_node).select { |def_node| test_case_name?(def_node.method_name) }
|
48
|
+
|
49
|
+
# Support Active Support's `test 'example' { ... }` method.
|
50
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Testing/Declarative.html
|
51
|
+
test_blocks = class_node.each_descendant(:block).select { |block_node| block_node.method?(:test) }
|
52
|
+
|
53
|
+
test_cases + test_blocks
|
47
54
|
end
|
48
55
|
|
49
56
|
def lifecycle_hooks(class_node)
|
@@ -82,11 +89,14 @@ module RuboCop
|
|
82
89
|
|
83
90
|
def assertion?(node)
|
84
91
|
node.send_type? &&
|
85
|
-
ASSERTION_PREFIXES.any?
|
92
|
+
ASSERTION_PREFIXES.any? do |prefix|
|
93
|
+
method_name = node.method_name.to_s
|
94
|
+
method_name == FLUNK || method_name.start_with?(prefix)
|
95
|
+
end
|
86
96
|
end
|
87
97
|
|
88
98
|
def assertion_method?(method_name)
|
89
|
-
ASSERTION_METHODS.include?(method_name)
|
99
|
+
method_name == FLUNK || ASSERTION_METHODS.include?(method_name)
|
90
100
|
end
|
91
101
|
|
92
102
|
def lifecycle_hook_method?(node)
|
data/relnotes/v0.11.1.md
ADDED
data/relnotes/v0.12.0.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#124](https://github.com/rubocop/rubocop-minitest/pull/124): Add new `Minitest/NoAssertions` cop. ([@ghiculescu][])
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
|
7
|
+
* [#129](https://github.com/rubocop/rubocop-minitest/pull/129): Drop Ruby 2.4 support. ([@koic][])
|
8
|
+
|
9
|
+
[@ghiculescu]: https://github.com/ghiculescu
|
10
|
+
[@koic]: https://github.com/koic
|
data/relnotes/v0.12.1.md
ADDED
data/relnotes/v0.13.0.md
ADDED
data/relnotes/v0.14.0.md
ADDED
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.5.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',
|
@@ -25,15 +25,14 @@ task verify_cops_documentation: :generate_cops_documentation do
|
|
25
25
|
# Output diff before raising error
|
26
26
|
sh('GIT_PAGER=cat git diff docs')
|
27
27
|
|
28
|
-
warn 'The docs directory is out of sync. '
|
29
|
-
'Run `rake generate_cops_documentation` and commit the results.'
|
28
|
+
warn 'The docs directory is out of sync. Run `rake generate_cops_documentation` and commit the results.'
|
30
29
|
exit!
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
33
|
desc 'Syntax check for the documentation comments'
|
35
34
|
task documentation_syntax_check: :yard_for_generate_documentation do
|
36
|
-
require 'parser/
|
35
|
+
require 'parser/ruby30'
|
37
36
|
|
38
37
|
ok = true
|
39
38
|
YARD::Registry.load!
|
@@ -46,17 +45,15 @@ task documentation_syntax_check: :yard_for_generate_documentation do
|
|
46
45
|
end
|
47
46
|
|
48
47
|
examples.to_a.each do |example|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
ok = false
|
59
|
-
end
|
48
|
+
buffer = Parser::Source::Buffer.new('<code>', 1)
|
49
|
+
buffer.source = example.text
|
50
|
+
parser = Parser::Ruby30.new(RuboCop::AST::Builder.new)
|
51
|
+
parser.diagnostics.all_errors_are_fatal = true
|
52
|
+
parser.parse(buffer)
|
53
|
+
rescue Parser::SyntaxError => e
|
54
|
+
path = example.object.file
|
55
|
+
puts "#{path}: Syntax Error in an example. #{e}"
|
56
|
+
ok = false
|
60
57
|
end
|
61
58
|
end
|
62
59
|
abort unless ok
|
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.14.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: 2021-
|
13
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/rubocop/cop/minitest/global_expectations.rb
|
106
106
|
- lib/rubocop/cop/minitest/literal_as_actual_argument.rb
|
107
107
|
- lib/rubocop/cop/minitest/multiple_assertions.rb
|
108
|
+
- lib/rubocop/cop/minitest/no_assertions.rb
|
108
109
|
- lib/rubocop/cop/minitest/refute_empty.rb
|
109
110
|
- lib/rubocop/cop/minitest/refute_equal.rb
|
110
111
|
- lib/rubocop/cop/minitest/refute_false.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/rubocop/cop/minitest/refute_path_exists.rb
|
118
119
|
- lib/rubocop/cop/minitest/refute_respond_to.rb
|
119
120
|
- lib/rubocop/cop/minitest/test_method_name.rb
|
121
|
+
- lib/rubocop/cop/minitest/unreachable_assertion.rb
|
120
122
|
- lib/rubocop/cop/minitest/unspecified_exception.rb
|
121
123
|
- lib/rubocop/cop/minitest_cops.rb
|
122
124
|
- lib/rubocop/cop/mixin/argument_range_helper.rb
|
@@ -134,6 +136,11 @@ files:
|
|
134
136
|
- relnotes/v0.10.2.md
|
135
137
|
- relnotes/v0.10.3.md
|
136
138
|
- relnotes/v0.11.0.md
|
139
|
+
- relnotes/v0.11.1.md
|
140
|
+
- relnotes/v0.12.0.md
|
141
|
+
- relnotes/v0.12.1.md
|
142
|
+
- relnotes/v0.13.0.md
|
143
|
+
- relnotes/v0.14.0.md
|
137
144
|
- relnotes/v0.2.0.md
|
138
145
|
- relnotes/v0.2.1.md
|
139
146
|
- relnotes/v0.3.0.md
|
@@ -158,7 +165,7 @@ metadata:
|
|
158
165
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
159
166
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
160
167
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
161
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
168
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.14
|
162
169
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
163
170
|
post_install_message:
|
164
171
|
rdoc_options: []
|
@@ -168,14 +175,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
175
|
requirements:
|
169
176
|
- - ">="
|
170
177
|
- !ruby/object:Gem::Version
|
171
|
-
version: 2.
|
178
|
+
version: 2.5.0
|
172
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
180
|
requirements:
|
174
181
|
- - ">="
|
175
182
|
- !ruby/object:Gem::Version
|
176
183
|
version: '0'
|
177
184
|
requirements: []
|
178
|
-
rubygems_version: 3.2.
|
185
|
+
rubygems_version: 3.2.18
|
179
186
|
signing_key:
|
180
187
|
specification_version: 4
|
181
188
|
summary: Automatic Minitest code style checking tool.
|