rubocop-minitest 0.32.1 → 0.33.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/lib/rubocop/cop/minitest/assert_equal.rb +34 -2
- data/lib/rubocop/cop/minitest/assert_match.rb +44 -3
- data/lib/rubocop/cop/minitest/assert_operator.rb +5 -1
- data/lib/rubocop/cop/minitest/refute_equal.rb +24 -28
- data/lib/rubocop/cop/minitest/refute_match.rb +46 -3
- data/lib/rubocop/cop/minitest/refute_operator.rb +5 -1
- data/lib/rubocop/minitest/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9952135d079a3cd02bea1c521f30f9a15eca9614caa6730c84d0afce7fca845
|
4
|
+
data.tar.gz: a11c62c0872b7abb891151770cc9008e1c43f0e8753b8371b85ba8c47142bd05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16fb13dc153d36bd4479690fc2be96dcfc119e9430271231266ba8b150c79871ce1ee417020c9af9a13c31928ea3afd97f23156c975d17ca1be1e2f9f9937770
|
7
|
+
data.tar.gz: f8bd286ee337818358b5e87bb5f375a6d03f2028de3f55481f0a8788013fe4f32314e90985fe967d7a83218dd3c8da0684cdc3b5e998a96f662e644e93c4afd8
|
@@ -9,14 +9,46 @@ module RuboCop
|
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# assert("rubocop-minitest" == actual)
|
12
|
+
# assert_operator("rubocop-minitest", :==, actual)
|
12
13
|
#
|
13
14
|
# # good
|
14
15
|
# assert_equal("rubocop-minitest", actual)
|
15
16
|
#
|
16
17
|
class AssertEqual < Base
|
17
|
-
|
18
|
+
include ArgumentRangeHelper
|
19
|
+
extend AutoCorrector
|
18
20
|
|
19
|
-
|
21
|
+
MSG = 'Prefer using `assert_equal(%<preferred>s)`.'
|
22
|
+
RESTRICT_ON_SEND = %i[assert assert_operator].freeze
|
23
|
+
|
24
|
+
def_node_matcher :assert_equal, <<~PATTERN
|
25
|
+
{
|
26
|
+
(send nil? :assert (send $_ :== $_) $...)
|
27
|
+
(send nil? :assert_operator $_ (sym :==) $_ $...)
|
28
|
+
}
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
# rubocop:disable Metrics/AbcSize
|
32
|
+
def on_send(node)
|
33
|
+
assert_equal(node) do |expected, actual, rest_args|
|
34
|
+
basic_arguments = "#{expected.source}, #{actual.source}"
|
35
|
+
preferred = (message_arg = rest_args.first) ? "#{basic_arguments}, #{message_arg.source}" : basic_arguments
|
36
|
+
message = format(MSG, preferred: preferred)
|
37
|
+
|
38
|
+
add_offense(node, message: message) do |corrector|
|
39
|
+
corrector.replace(node.loc.selector, 'assert_equal')
|
40
|
+
|
41
|
+
range = if node.method?(:assert)
|
42
|
+
node.first_argument
|
43
|
+
else
|
44
|
+
node.first_argument.source_range.begin.join(node.arguments[2].source_range.end)
|
45
|
+
end
|
46
|
+
|
47
|
+
corrector.replace(range, basic_arguments)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/AbcSize
|
20
52
|
end
|
21
53
|
end
|
22
54
|
end
|
@@ -11,6 +11,7 @@ module RuboCop
|
|
11
11
|
# assert(matcher.match(string))
|
12
12
|
# assert(matcher.match?(string))
|
13
13
|
# assert(matcher =~ string)
|
14
|
+
# assert_operator(matcher, :=~, string)
|
14
15
|
# assert(matcher.match(string), 'message')
|
15
16
|
#
|
16
17
|
# # good
|
@@ -18,10 +19,50 @@ module RuboCop
|
|
18
19
|
# assert_match(matcher, string, 'message')
|
19
20
|
#
|
20
21
|
class AssertMatch < Base
|
21
|
-
|
22
|
+
include ArgumentRangeHelper
|
23
|
+
extend AutoCorrector
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
MSG = 'Prefer using `assert_match(%<preferred>s)`.'
|
26
|
+
RESTRICT_ON_SEND = %i[assert assert_operator].freeze
|
27
|
+
|
28
|
+
def_node_matcher :assert_match, <<~PATTERN
|
29
|
+
{
|
30
|
+
(send nil? :assert (send $_ {:match :match? :=~} $_) $...)
|
31
|
+
(send nil? :assert_operator $_ (sym :=~) $_ $...)
|
32
|
+
}
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
36
|
+
def on_send(node)
|
37
|
+
assert_match(node) do |expected, actual, rest_args|
|
38
|
+
basic_arguments = order_expected_and_actual(expected, actual)
|
39
|
+
preferred = (message_arg = rest_args.first) ? "#{basic_arguments}, #{message_arg.source}" : basic_arguments
|
40
|
+
message = format(MSG, preferred: preferred)
|
41
|
+
|
42
|
+
add_offense(node, message: message) do |corrector|
|
43
|
+
corrector.replace(node.loc.selector, 'assert_match')
|
44
|
+
|
45
|
+
range = if node.method?(:assert)
|
46
|
+
node.first_argument
|
47
|
+
else
|
48
|
+
node.first_argument.source_range.begin.join(node.arguments[2].source_range.end)
|
49
|
+
end
|
50
|
+
|
51
|
+
corrector.replace(range, basic_arguments)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
# rubocop:enable Metrics/AbcSize
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def order_expected_and_actual(expected, actual)
|
60
|
+
if actual.regexp_type?
|
61
|
+
[actual, expected]
|
62
|
+
else
|
63
|
+
[expected, actual]
|
64
|
+
end.map(&:source).join(', ')
|
65
|
+
end
|
25
66
|
end
|
26
67
|
end
|
27
68
|
end
|
@@ -18,10 +18,14 @@ module RuboCop
|
|
18
18
|
|
19
19
|
MSG = 'Prefer using `assert_operator(%<new_arguments>s)`.'
|
20
20
|
RESTRICT_ON_SEND = %i[assert].freeze
|
21
|
+
ALLOWED_OPERATORS = [:[]].freeze
|
21
22
|
|
22
23
|
def on_send(node)
|
23
24
|
first_argument = node.first_argument
|
24
|
-
return unless first_argument.respond_to?(:
|
25
|
+
return unless first_argument.respond_to?(:binary_operation?) && first_argument.binary_operation?
|
26
|
+
|
27
|
+
operator = first_argument.to_a[1]
|
28
|
+
return if ALLOWED_OPERATORS.include?(operator)
|
25
29
|
|
26
30
|
new_arguments = build_new_arguments(node)
|
27
31
|
|
@@ -9,6 +9,9 @@ module RuboCop
|
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# assert("rubocop-minitest" != actual)
|
12
|
+
# refute("rubocop-minitest" == actual)
|
13
|
+
# assert_operator("rubocop-minitest", :!=, actual)
|
14
|
+
# refute_operator("rubocop-minitest", :==, actual)
|
12
15
|
#
|
13
16
|
# # good
|
14
17
|
# refute_equal("rubocop-minitest", actual)
|
@@ -18,45 +21,38 @@ module RuboCop
|
|
18
21
|
extend AutoCorrector
|
19
22
|
|
20
23
|
MSG = 'Prefer using `refute_equal(%<preferred>s)`.'
|
21
|
-
RESTRICT_ON_SEND = %i[assert].freeze
|
22
|
-
|
23
|
-
def_node_matcher :
|
24
|
-
|
24
|
+
RESTRICT_ON_SEND = %i[assert refute assert_operator refute_operator].freeze
|
25
|
+
|
26
|
+
def_node_matcher :refute_equal, <<~PATTERN
|
27
|
+
{
|
28
|
+
(send nil? :assert (send $_ :!= $_) $...)
|
29
|
+
(send nil? :refute (send $_ :== $_) $...)
|
30
|
+
(send nil? :assert_operator $_ (sym :!=) $_ $...)
|
31
|
+
(send nil? :refute_operator $_ (sym :==) $_ $...)
|
32
|
+
}
|
25
33
|
PATTERN
|
26
34
|
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
27
36
|
def on_send(node)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
assert_not_equal(node) do |expected, actual|
|
37
|
+
refute_equal(node) do |expected, actual, rest_args|
|
38
|
+
basic_arguments = "#{expected.source}, #{actual.source}"
|
39
|
+
preferred = (message_arg = rest_args.first) ? "#{basic_arguments}, #{message_arg.source}" : basic_arguments
|
32
40
|
message = format(MSG, preferred: preferred)
|
33
41
|
|
34
42
|
add_offense(node, message: message) do |corrector|
|
35
43
|
corrector.replace(node.loc.selector, 'refute_equal')
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
private
|
45
|
+
range = if node.method?(:assert) || node.method?(:refute)
|
46
|
+
node.first_argument
|
47
|
+
else
|
48
|
+
node.first_argument.source_range.begin.join(node.arguments[2].source_range.end)
|
49
|
+
end
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def original_usage(first_part, custom_message)
|
50
|
-
[first_part, custom_message].compact.join(', ')
|
51
|
-
end
|
52
|
-
|
53
|
-
def process_not_equal(node)
|
54
|
-
assert_not_equal(node) do |first_arg, second_arg, rest_args|
|
55
|
-
custom_message = rest_args.first
|
56
|
-
|
57
|
-
preferred_usage(first_arg, second_arg, custom_message)
|
51
|
+
corrector.replace(range, basic_arguments)
|
52
|
+
end
|
58
53
|
end
|
59
54
|
end
|
55
|
+
# rubocop:enable Metrics/AbcSize
|
60
56
|
end
|
61
57
|
end
|
62
58
|
end
|
@@ -11,6 +11,8 @@ module RuboCop
|
|
11
11
|
# refute(matcher.match(string))
|
12
12
|
# refute(matcher.match?(string))
|
13
13
|
# refute(matcher =~ string)
|
14
|
+
# refute_operator(matcher, :=~, string)
|
15
|
+
# assert_operator(matcher, :!~, string)
|
14
16
|
# refute(matcher.match(string), 'message')
|
15
17
|
#
|
16
18
|
# # good
|
@@ -18,10 +20,51 @@ module RuboCop
|
|
18
20
|
# refute_match(matcher, string, 'message')
|
19
21
|
#
|
20
22
|
class RefuteMatch < Base
|
21
|
-
|
23
|
+
include ArgumentRangeHelper
|
24
|
+
extend AutoCorrector
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
MSG = 'Prefer using `refute_match(%<preferred>s)`.'
|
27
|
+
RESTRICT_ON_SEND = %i[refute refute_operator assert_operator].freeze
|
28
|
+
|
29
|
+
def_node_matcher :refute_match, <<~PATTERN
|
30
|
+
{
|
31
|
+
(send nil? :refute (send $_ {:match :match? :=~} $_) $...)
|
32
|
+
(send nil? :refute_operator $_ (sym :=~) $_ $...)
|
33
|
+
(send nil? :assert_operator $_ (sym :!~) $_ $...)
|
34
|
+
}
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
# rubocop:disable Metrics/AbcSize
|
38
|
+
def on_send(node)
|
39
|
+
refute_match(node) do |expected, actual, rest_args|
|
40
|
+
basic_arguments = order_expected_and_actual(expected, actual)
|
41
|
+
preferred = (message_arg = rest_args.first) ? "#{basic_arguments}, #{message_arg.source}" : basic_arguments
|
42
|
+
message = format(MSG, preferred: preferred)
|
43
|
+
|
44
|
+
add_offense(node, message: message) do |corrector|
|
45
|
+
corrector.replace(node.loc.selector, 'refute_match')
|
46
|
+
|
47
|
+
range = if node.method?(:refute)
|
48
|
+
node.first_argument
|
49
|
+
else
|
50
|
+
node.first_argument.source_range.begin.join(node.arguments[2].source_range.end)
|
51
|
+
end
|
52
|
+
|
53
|
+
corrector.replace(range, basic_arguments)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
# rubocop:enable Metrics/AbcSize
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def order_expected_and_actual(expected, actual)
|
62
|
+
if actual.regexp_type?
|
63
|
+
[actual, expected]
|
64
|
+
else
|
65
|
+
[expected, actual]
|
66
|
+
end.map(&:source).join(', ')
|
67
|
+
end
|
25
68
|
end
|
26
69
|
end
|
27
70
|
end
|
@@ -18,10 +18,14 @@ module RuboCop
|
|
18
18
|
|
19
19
|
MSG = 'Prefer using `refute_operator(%<new_arguments>s)`.'
|
20
20
|
RESTRICT_ON_SEND = %i[refute].freeze
|
21
|
+
ALLOWED_OPERATORS = [:[]].freeze
|
21
22
|
|
22
23
|
def on_send(node)
|
23
24
|
first_argument = node.first_argument
|
24
|
-
return unless first_argument.respond_to?(:
|
25
|
+
return unless first_argument.respond_to?(:binary_operation?) && first_argument.binary_operation?
|
26
|
+
|
27
|
+
operator = first_argument.to_a[1]
|
28
|
+
return if ALLOWED_OPERATORS.include?(operator)
|
25
29
|
|
26
30
|
new_arguments = build_new_arguments(node)
|
27
31
|
|
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.33.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-
|
13
|
+
date: 2023-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -117,7 +117,7 @@ metadata:
|
|
117
117
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
118
118
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
119
119
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
120
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
120
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.33
|
121
121
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
122
122
|
rubygems_mfa_required: 'true'
|
123
123
|
post_install_message:
|