rubocop-minitest 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/rubocop/cop/minitest/assert_respond_to.rb +13 -5
- data/lib/rubocop/cop/minitest/refute_respond_to.rb +13 -5
- data/lib/rubocop/minitest/version.rb +1 -1
- data/manual/cops_minitest.md +4 -0
- data/relnotes/v0.4.1.md +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930866a6157741e50512335bb341add3271a010ce7297d47a2ea439494b48bd1
|
4
|
+
data.tar.gz: 6e3583932fa0d49db8ca8a77f4f8c47b36d4e13bd978f4ee91075190f0e646ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a84adc4ef08e2c434ef214ac0351f5943ef2fc55b24e7e8d16be6a423d5e2a19e189ec1e23f6bad5ae8f1a23595332949f6f318295680d0ec854efb084d2ff0
|
7
|
+
data.tar.gz: 45725285a52705d75dc544ecc13d644e38cae8338c8fe070599def10ce272357bbc89cd26f9188300cf4b0f8a1d1a82818406242a36ff6f9102066fb052a3ca4
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.4.1 (2019-11-10)
|
6
|
+
|
7
|
+
### Bug fixes
|
8
|
+
|
9
|
+
* [#39](https://github.com/rubocop-hq/rubocop-minitest/issues/39): Fix an incorrect autocorrect for `Minitest/AssertRespondTo` and `Minitest/RefuteRespondTo` when using assertion method calling `respond_to` with receiver omitted. ([@koic][])
|
10
|
+
|
5
11
|
## 0.4.0 (2019-11-07)
|
6
12
|
|
7
13
|
### New features
|
@@ -10,10 +10,12 @@ module RuboCop
|
|
10
10
|
# # bad
|
11
11
|
# assert(object.respond_to?(:some_method))
|
12
12
|
# assert(object.respond_to?(:some_method), 'the message')
|
13
|
+
# assert(respond_to?(:some_method))
|
13
14
|
#
|
14
15
|
# # good
|
15
16
|
# assert_respond_to(object, :some_method)
|
16
17
|
# assert_respond_to(object, :some_method, 'the message')
|
18
|
+
# assert_respond_to(self, some_method)
|
17
19
|
#
|
18
20
|
class AssertRespondTo < Cop
|
19
21
|
MSG = 'Prefer using `assert_respond_to(%<preferred>s)` over ' \
|
@@ -26,9 +28,8 @@ module RuboCop
|
|
26
28
|
def on_send(node)
|
27
29
|
assert_with_respond_to(node) do |over, object, method, rest_args|
|
28
30
|
custom_message = rest_args.first
|
29
|
-
preferred =
|
30
|
-
|
31
|
-
over = [over, custom_message].compact.map(&:source).join(', ')
|
31
|
+
preferred = build_preferred_arguments(object, method, custom_message)
|
32
|
+
over = [over, custom_message].compact.map(&:source).join(', ')
|
32
33
|
message = format(MSG, preferred: preferred, over: over)
|
33
34
|
add_offense(node, message: message)
|
34
35
|
end
|
@@ -38,13 +39,20 @@ module RuboCop
|
|
38
39
|
lambda do |corrector|
|
39
40
|
assert_with_respond_to(node) do |_, object, method, rest_args|
|
40
41
|
custom_message = rest_args.first
|
41
|
-
preferred =
|
42
|
-
.compact.map(&:source).join(', ')
|
42
|
+
preferred = build_preferred_arguments(object, method, custom_message)
|
43
43
|
replacement = "assert_respond_to(#{preferred})"
|
44
44
|
corrector.replace(node.loc.expression, replacement)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_preferred_arguments(receiver, method, message)
|
52
|
+
receiver = receiver ? receiver.source : 'self'
|
53
|
+
|
54
|
+
[receiver, method.source, message&.source].compact.join(', ')
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -10,10 +10,12 @@ module RuboCop
|
|
10
10
|
# # bad
|
11
11
|
# refute(object.respond_to?(:some_method))
|
12
12
|
# refute(object.respond_to?(:some_method), 'the message')
|
13
|
+
# refute(respond_to?(:some_method))
|
13
14
|
#
|
14
15
|
# # good
|
15
16
|
# refute_respond_to(object, :some_method)
|
16
17
|
# refute_respond_to(object, :some_method, 'the message')
|
18
|
+
# refute_respond_to(self, :some_method)
|
17
19
|
#
|
18
20
|
class RefuteRespondTo < Cop
|
19
21
|
MSG = 'Prefer using `refute_respond_to(%<preferred>s)` over ' \
|
@@ -26,9 +28,8 @@ module RuboCop
|
|
26
28
|
def on_send(node)
|
27
29
|
refute_with_respond_to(node) do |over, object, method, rest_args|
|
28
30
|
custom_message = rest_args.first
|
29
|
-
preferred =
|
30
|
-
|
31
|
-
over = [over, custom_message].compact.map(&:source).join(', ')
|
31
|
+
preferred = build_preferred_arguments(object, method, custom_message)
|
32
|
+
over = [over, custom_message].compact.map(&:source).join(', ')
|
32
33
|
message = format(MSG, preferred: preferred, over: over)
|
33
34
|
add_offense(node, message: message)
|
34
35
|
end
|
@@ -38,13 +39,20 @@ module RuboCop
|
|
38
39
|
lambda do |corrector|
|
39
40
|
refute_with_respond_to(node) do |_, object, method, rest_args|
|
40
41
|
custom_message = rest_args.first
|
41
|
-
preferred =
|
42
|
-
.compact.map(&:source).join(', ')
|
42
|
+
preferred = build_preferred_arguments(object, method, custom_message)
|
43
43
|
replacement = "refute_respond_to(#{preferred})"
|
44
44
|
corrector.replace(node.loc.expression, replacement)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_preferred_arguments(receiver, method, message)
|
52
|
+
receiver = receiver ? receiver.source : 'self'
|
53
|
+
|
54
|
+
[receiver, method.source, message&.source].compact.join(', ')
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/manual/cops_minitest.md
CHANGED
@@ -138,10 +138,12 @@ over `assert(object.respond_to?(:some_method))`.
|
|
138
138
|
# bad
|
139
139
|
assert(object.respond_to?(:some_method))
|
140
140
|
assert(object.respond_to?(:some_method), 'the message')
|
141
|
+
assert(respond_to?(:some_method))
|
141
142
|
|
142
143
|
# good
|
143
144
|
assert_respond_to(object, :some_method)
|
144
145
|
assert_respond_to(object, :some_method, 'the message')
|
146
|
+
assert_respond_to(self, some_method)
|
145
147
|
```
|
146
148
|
|
147
149
|
### References
|
@@ -337,10 +339,12 @@ over `refute(object.respond_to?(:some_method))`.
|
|
337
339
|
# bad
|
338
340
|
refute(object.respond_to?(:some_method))
|
339
341
|
refute(object.respond_to?(:some_method), 'the message')
|
342
|
+
refute(respond_to?(:some_method))
|
340
343
|
|
341
344
|
# good
|
342
345
|
refute_respond_to(object, :some_method)
|
343
346
|
refute_respond_to(object, :some_method, 'the message')
|
347
|
+
refute_respond_to(self, :some_method)
|
344
348
|
```
|
345
349
|
|
346
350
|
### References
|
data/relnotes/v0.4.1.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
### Bug fixes
|
2
|
+
|
3
|
+
* [#39](https://github.com/rubocop-hq/rubocop-minitest/issues/39): Fix an incorrect autocorrect for `Minitest/AssertRespondTo` and `Minitest/RefuteRespondTo` when using assertion method calling `respond_to` with receiver omitted. ([@koic][])
|
4
|
+
|
5
|
+
[@koic]: https://github.com/koic
|
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.
|
4
|
+
version: 0.4.1
|
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: 2019-11-
|
13
|
+
date: 2019-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- relnotes/v0.2.1.md
|
97
97
|
- relnotes/v0.3.0.md
|
98
98
|
- relnotes/v0.4.0.md
|
99
|
+
- relnotes/v0.4.1.md
|
99
100
|
- rubocop-minitest.gemspec
|
100
101
|
- tasks/cops_documentation.rake
|
101
102
|
- tasks/cut_release.rake
|