rubocop-minitest 0.31.1 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +12 -0
- data/lib/rubocop/cop/minitest/assert_operator.rb +53 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +9 -4
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +16 -5
- data/lib/rubocop/cop/minitest/refute_operator.rb +53 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +9 -4
- data/lib/rubocop/cop/minitest_cops.rb +5 -3
- data/lib/rubocop/minitest/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3581920acff906161f98b5af290d613af4d257834817f55d6a607088754dc4d8
|
4
|
+
data.tar.gz: 1d19f60506d3e2693ce52d4eaf63b8fa92b00f2a6eda4b499df7920559b29bf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c297aa12f347d2fb0ee9d6fcdf52728498f7d3d148fc4b1a3ad26f1c0f9329fbaf8773601d330670a69ab7a3dae19d9702e27c7f5ffff6fa8cc7519f669a7a6
|
7
|
+
data.tar.gz: d69e427b9f613c07a87a83ae24fc694e3fba7322e3c44f4548771645879383a5f713cca74e56061c509c4a5229c633bc52a905af5f97fdcae6af576608be5c6a
|
data/config/default.yml
CHANGED
@@ -59,6 +59,12 @@ Minitest/AssertNil:
|
|
59
59
|
Enabled: true
|
60
60
|
VersionAdded: '0.1'
|
61
61
|
|
62
|
+
Minitest/AssertOperator:
|
63
|
+
Description: 'This cop enforces the use of `assert_operator(expected, :<, actual)` over `assert(expected < actual)`.'
|
64
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-operator'
|
65
|
+
Enabled: pending
|
66
|
+
VersionAdded: '0.32'
|
67
|
+
|
62
68
|
Minitest/AssertOutput:
|
63
69
|
Description: 'This cop checks for opportunities to use `assert_output`.'
|
64
70
|
StyleGuide: 'https://minitest.rubystyle.guide/#assert-output'
|
@@ -248,6 +254,12 @@ Minitest/RefuteNil:
|
|
248
254
|
Enabled: true
|
249
255
|
VersionAdded: '0.2'
|
250
256
|
|
257
|
+
Minitest/RefuteOperator:
|
258
|
+
Description: 'This cop enforces the use of `refute_operator(expected, :<, actual)` over `refute(expected < actual)`.'
|
259
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-operator'
|
260
|
+
Enabled: pending
|
261
|
+
VersionAdded: '0.32'
|
262
|
+
|
251
263
|
Minitest/RefutePathExists:
|
252
264
|
Description: 'This cop enforces the test to use `refute_path_exists` instead of using `refute(File.exist?(path))`.'
|
253
265
|
StyleGuide: 'https://minitest.rubystyle.guide/#refute-path-exists'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# Enforces the use of `assert_operator(expected, :<, actual)` over `assert(expected < actual)`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# assert(expected < actual)
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# assert_operator(expected, :<, actual)
|
15
|
+
#
|
16
|
+
class AssertOperator < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Prefer using `assert_operator(%<new_arguments>s)`.'
|
20
|
+
RESTRICT_ON_SEND = %i[assert].freeze
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
return unless node.first_argument.operator_method?
|
24
|
+
|
25
|
+
new_arguments = build_new_arguments(node)
|
26
|
+
|
27
|
+
add_offense(node, message: format(MSG, new_arguments: new_arguments)) do |corrector|
|
28
|
+
corrector.replace(node.loc.selector, 'assert_operator')
|
29
|
+
|
30
|
+
corrector.replace(range_of_arguments(node), new_arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def build_new_arguments(node)
|
37
|
+
lhs, op, rhs = *node.first_argument
|
38
|
+
new_arguments = "#{lhs.source}, :#{op}, #{rhs.source}"
|
39
|
+
|
40
|
+
if node.arguments.count == 2
|
41
|
+
new_arguments << ", #{node.last_argument.source}"
|
42
|
+
else
|
43
|
+
new_arguments
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def range_of_arguments(node)
|
48
|
+
node.first_argument.source_range.begin.join(node.last_argument.source_range.end)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -30,20 +30,25 @@ module RuboCop
|
|
30
30
|
def on_send(node)
|
31
31
|
assert_file_exists(node) do |path, failure_message|
|
32
32
|
failure_message = failure_message.first
|
33
|
-
good_method = build_good_method(path, failure_message)
|
33
|
+
good_method = build_good_method(node, path, failure_message)
|
34
34
|
message = format(MSG, good_method: good_method)
|
35
35
|
|
36
36
|
add_offense(node, message: message) do |corrector|
|
37
|
-
corrector.replace(node,
|
37
|
+
corrector.replace(node.loc.selector, 'assert_path_exists')
|
38
|
+
corrector.replace(node.first_argument, path.source)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
private
|
43
44
|
|
44
|
-
def build_good_method(path, message)
|
45
|
+
def build_good_method(node, path, message)
|
45
46
|
args = [path.source, message&.source].compact.join(', ')
|
46
|
-
|
47
|
+
if node.parenthesized?
|
48
|
+
"assert_path_exists(#{args})"
|
49
|
+
else
|
50
|
+
"assert_path_exists #{args}"
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -27,24 +27,35 @@ module RuboCop
|
|
27
27
|
def on_send(node)
|
28
28
|
return unless node.method?(:assert_equal)
|
29
29
|
|
30
|
-
expected, actual,
|
30
|
+
expected, actual, _message = *node.arguments
|
31
31
|
return unless actual&.recursive_basic_literal?
|
32
32
|
return if expected.recursive_basic_literal?
|
33
33
|
|
34
34
|
add_offense(all_arguments_range(node)) do |corrector|
|
35
|
-
autocorrect(corrector, node, expected, actual
|
35
|
+
autocorrect(corrector, node, expected, actual)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
private
|
40
|
+
|
41
|
+
def autocorrect(corrector, node, expected, actual)
|
40
42
|
new_actual_source = if actual.hash_type? && !actual.braces?
|
41
43
|
"{#{actual.source}}"
|
42
44
|
else
|
43
45
|
actual.source
|
44
46
|
end
|
45
|
-
arguments = [new_actual_source, expected.source, message&.source].compact.join(', ')
|
46
47
|
|
47
|
-
corrector.replace(
|
48
|
+
corrector.replace(expected, new_actual_source)
|
49
|
+
corrector.replace(actual, expected.source)
|
50
|
+
|
51
|
+
wrap_with_parentheses(corrector, node) if !node.parenthesized? && actual.hash_type?
|
52
|
+
end
|
53
|
+
|
54
|
+
def wrap_with_parentheses(corrector, node)
|
55
|
+
range = node.loc.selector.end.join(node.first_argument.source_range.begin)
|
56
|
+
|
57
|
+
corrector.replace(range, '(')
|
58
|
+
corrector.insert_after(node, ')')
|
48
59
|
end
|
49
60
|
end
|
50
61
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# Enforces the use of `refute_operator(expected, :<, actual)` over `refute(expected < actual)`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# refute(expected < actual)
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# refute_operator(expected, :<, actual)
|
15
|
+
#
|
16
|
+
class RefuteOperator < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Prefer using `refute_operator(%<new_arguments>s)`.'
|
20
|
+
RESTRICT_ON_SEND = %i[refute].freeze
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
return unless node.first_argument.operator_method?
|
24
|
+
|
25
|
+
new_arguments = build_new_arguments(node)
|
26
|
+
|
27
|
+
add_offense(node, message: format(MSG, new_arguments: new_arguments)) do |corrector|
|
28
|
+
corrector.replace(node.loc.selector, 'refute_operator')
|
29
|
+
|
30
|
+
corrector.replace(range_of_arguments(node), new_arguments)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def build_new_arguments(node)
|
37
|
+
lhs, op, rhs = *node.first_argument
|
38
|
+
new_arguments = "#{lhs.source}, :#{op}, #{rhs.source}"
|
39
|
+
|
40
|
+
if node.arguments.count == 2
|
41
|
+
new_arguments << ", #{node.last_argument.source}"
|
42
|
+
else
|
43
|
+
new_arguments
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def range_of_arguments(node)
|
48
|
+
node.first_argument.source_range.begin.join(node.last_argument.source_range.end)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -30,20 +30,25 @@ module RuboCop
|
|
30
30
|
def on_send(node)
|
31
31
|
refute_file_exists(node) do |path, failure_message|
|
32
32
|
failure_message = failure_message.first
|
33
|
-
good_method = build_good_method(path, failure_message)
|
33
|
+
good_method = build_good_method(node, path, failure_message)
|
34
34
|
message = format(MSG, good_method: good_method)
|
35
35
|
|
36
36
|
add_offense(node, message: message) do |corrector|
|
37
|
-
corrector.replace(node,
|
37
|
+
corrector.replace(node.loc.selector, 'refute_path_exists')
|
38
|
+
corrector.replace(node.first_argument, path.source)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
private
|
43
44
|
|
44
|
-
def build_good_method(path, message)
|
45
|
+
def build_good_method(node, path, message)
|
45
46
|
args = [path.source, message&.source].compact.join(', ')
|
46
|
-
|
47
|
+
if node.parenthesized?
|
48
|
+
"refute_path_exists(#{args})"
|
49
|
+
else
|
50
|
+
"refute_path_exists #{args}"
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -11,6 +11,7 @@ require_relative 'minitest/assert_empty'
|
|
11
11
|
require_relative 'minitest/assert_empty_literal'
|
12
12
|
require_relative 'minitest/assert_equal'
|
13
13
|
require_relative 'minitest/assert_in_delta'
|
14
|
+
require_relative 'minitest/assert_operator'
|
14
15
|
require_relative 'minitest/assert_predicate'
|
15
16
|
require_relative 'minitest/assert_raises_compound_body'
|
16
17
|
require_relative 'minitest/assert_raises_with_regexp_argument'
|
@@ -42,11 +43,12 @@ require_relative 'minitest/refute_empty'
|
|
42
43
|
require_relative 'minitest/refute_false'
|
43
44
|
require_relative 'minitest/refute_equal'
|
44
45
|
require_relative 'minitest/refute_in_delta'
|
45
|
-
require_relative 'minitest/refute_kind_of'
|
46
|
-
require_relative 'minitest/refute_nil'
|
47
46
|
require_relative 'minitest/refute_includes'
|
48
|
-
require_relative 'minitest/refute_match'
|
49
47
|
require_relative 'minitest/refute_instance_of'
|
48
|
+
require_relative 'minitest/refute_kind_of'
|
49
|
+
require_relative 'minitest/refute_match'
|
50
|
+
require_relative 'minitest/refute_nil'
|
51
|
+
require_relative 'minitest/refute_operator'
|
50
52
|
require_relative 'minitest/refute_path_exists'
|
51
53
|
require_relative 'minitest/refute_predicate'
|
52
54
|
require_relative 'minitest/refute_respond_to'
|
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.32.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: 2023-09-
|
13
|
+
date: 2023-09-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/rubocop/cop/minitest/assert_kind_of.rb
|
55
55
|
- lib/rubocop/cop/minitest/assert_match.rb
|
56
56
|
- lib/rubocop/cop/minitest/assert_nil.rb
|
57
|
+
- lib/rubocop/cop/minitest/assert_operator.rb
|
57
58
|
- lib/rubocop/cop/minitest/assert_output.rb
|
58
59
|
- lib/rubocop/cop/minitest/assert_path_exists.rb
|
59
60
|
- lib/rubocop/cop/minitest/assert_predicate.rb
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- lib/rubocop/cop/minitest/refute_kind_of.rb
|
84
85
|
- lib/rubocop/cop/minitest/refute_match.rb
|
85
86
|
- lib/rubocop/cop/minitest/refute_nil.rb
|
87
|
+
- lib/rubocop/cop/minitest/refute_operator.rb
|
86
88
|
- lib/rubocop/cop/minitest/refute_path_exists.rb
|
87
89
|
- lib/rubocop/cop/minitest/refute_predicate.rb
|
88
90
|
- lib/rubocop/cop/minitest/refute_respond_to.rb
|
@@ -115,7 +117,7 @@ metadata:
|
|
115
117
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
116
118
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
117
119
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
118
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
120
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.32
|
119
121
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
120
122
|
rubygems_mfa_required: 'true'
|
121
123
|
post_install_message:
|
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
135
|
- !ruby/object:Gem::Version
|
134
136
|
version: '0'
|
135
137
|
requirements: []
|
136
|
-
rubygems_version: 3.4.
|
138
|
+
rubygems_version: 3.4.19
|
137
139
|
signing_key:
|
138
140
|
specification_version: 4
|
139
141
|
summary: Automatic Minitest code style checking tool.
|