rubocop-minitest 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/rubocop/cop/minitest/assert_equal.rb +2 -31
- data/lib/rubocop/cop/minitest/global_expectations.rb +27 -20
- data/lib/rubocop/minitest/version.rb +1 -1
- data/manual/cops_minitest.md +7 -5
- data/relnotes/v0.8.0.md +12 -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: 6e766db856d11b13a5c3fbbf11a17a0e0fdbdda162195f11fbbc898c08670102
|
4
|
+
data.tar.gz: 5c223aa1303c61e17766a3c1be7e2641da280446450cbe8d93786b4542c624aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e1ef3c91cc1b9b55a6c26c9737fe6207cada7f48a3f78c40288650fa17b3efaeb4e740ab60ff12a532a4506f78e5c7fa823a840f6618791d0454f7071ddd29
|
7
|
+
data.tar.gz: c6eb92763493631a30e3bbf35efd62d3141a9ad0fa8365975cb96825f31454c0892ca249df6421b724e589b95c9098302c56572d55514f6b77b1b58d6feb3838
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.8.0 (2020-03-24)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#66](https://github.com/rubocop-hq/rubocop-minitest/issues/66): Support all expectations of `Minitest::Expectations` for `Minitest/GlobalExpectations` cop. ([@koic][])
|
10
|
+
|
11
|
+
### Bug fixes
|
12
|
+
|
13
|
+
* [#60](https://github.com/rubocop-hq/rubocop-minitest/issues/60): Fix `Minitest/GlobalExpectations` autocorrection for chained methods. ([@tejasbubane][])
|
14
|
+
* [#69](https://github.com/rubocop-hq/rubocop-minitest/pull/69): Fix a false negative for `Minitest/GlobalExpectations` cop when using a variable or a hash index for receiver. ([@koic][])
|
15
|
+
* [#71](https://github.com/rubocop-hq/rubocop-minitest/pull/71): Fix a false negative for `Minitest/AssertEqual` when an argument is enclosed in redundant parentheses. ([@koic][])
|
16
|
+
|
5
17
|
## 0.7.0 (2020-03-09)
|
6
18
|
|
7
19
|
### New features
|
@@ -14,38 +14,9 @@ module RuboCop
|
|
14
14
|
# assert_equal("rubocop-minitest", actual)
|
15
15
|
#
|
16
16
|
class AssertEqual < Cop
|
17
|
-
|
17
|
+
extend MinitestCopRule
|
18
18
|
|
19
|
-
|
20
|
-
'`assert(%<over>s)`.'
|
21
|
-
|
22
|
-
def_node_matcher :assert_equal, <<~PATTERN
|
23
|
-
(send nil? :assert $(send $_ :== $_) $...)
|
24
|
-
PATTERN
|
25
|
-
|
26
|
-
def on_send(node)
|
27
|
-
assert_equal(node) do |first_receiver_arg, expected, actual, rest_receiver_arg|
|
28
|
-
message = rest_receiver_arg.first
|
29
|
-
preferred = [expected.source, actual.source, message&.source]
|
30
|
-
.compact.join(', ')
|
31
|
-
over = [first_receiver_arg.source, message&.source].compact.join(', ')
|
32
|
-
|
33
|
-
offense_message = format(MSG, preferred: preferred, over: over)
|
34
|
-
|
35
|
-
add_offense(node, message: offense_message)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def autocorrect(node)
|
40
|
-
lambda do |corrector|
|
41
|
-
assert_equal(node) do |_, expected, actual|
|
42
|
-
corrector.replace(node.loc.selector, 'assert_equal')
|
43
|
-
|
44
|
-
replacement = [expected, actual].map(&:source).join(', ')
|
45
|
-
corrector.replace(first_argument_range(node), replacement)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
19
|
+
define_rule :assert, target_method: :==, preferred_method: :assert_equal
|
49
20
|
end
|
50
21
|
end
|
51
22
|
end
|
@@ -3,50 +3,57 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
# This
|
6
|
+
# This cop checks for deprecated global expectations
|
7
7
|
# and autocorrects them to use expect format.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# musts.must_equal expected_musts
|
12
|
+
# wonts.wont_match expected_wonts
|
13
|
+
# musts.must_raise TypeError
|
13
14
|
#
|
14
15
|
# # good
|
15
|
-
# _(
|
16
|
-
# _(
|
16
|
+
# _(musts).must_equal expected_musts
|
17
|
+
# _(wonts).wont_match expected_wonts
|
18
|
+
# _ { musts }.must_raise TypeError
|
17
19
|
class GlobalExpectations < Cop
|
18
|
-
MSG = '
|
20
|
+
MSG = 'Use `%<preferred>s` instead.'
|
19
21
|
|
20
22
|
VALUE_MATCHERS = %i[
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
must_be_empty must_equal must_be_close_to must_be_within_delta
|
24
|
+
must_be_within_epsilon must_include must_be_instance_of must_be_kind_of
|
25
|
+
must_match must_be_nil must_be must_respond_to must_be_same_as
|
26
|
+
path_must_exist path_wont_exist wont_be_empty wont_equal wont_be_close_to
|
27
|
+
wont_be_within_delta wont_be_within_epsilon wont_include wont_be_instance_of
|
28
|
+
wont_be_kind_of wont_match wont_be_nil wont_be wont_respond_to wont_be_same_as
|
29
|
+
].freeze
|
27
30
|
|
28
|
-
BLOCK_MATCHERS = %i[must_output must_raise must_throw].freeze
|
31
|
+
BLOCK_MATCHERS = %i[must_output must_raise must_be_silent must_throw].freeze
|
29
32
|
|
30
33
|
MATCHERS_STR = (VALUE_MATCHERS + BLOCK_MATCHERS).map do |m|
|
31
34
|
":#{m}"
|
32
35
|
end.join(' ').freeze
|
33
36
|
|
34
37
|
def_node_matcher :global_expectation?, <<~PATTERN
|
35
|
-
(send
|
38
|
+
(send {
|
39
|
+
(send _ _)
|
40
|
+
({lvar ivar cvar gvar} _)
|
41
|
+
(send {(send _ _) ({lvar ivar cvar gvar} _)} _ _)
|
42
|
+
} {#{MATCHERS_STR}} ...)
|
36
43
|
PATTERN
|
37
44
|
|
38
45
|
def on_send(node)
|
39
46
|
return unless global_expectation?(node)
|
40
47
|
|
41
|
-
message = format(MSG,
|
42
|
-
add_offense(node, message: message)
|
48
|
+
message = format(MSG, preferred: preferred_receiver(node))
|
49
|
+
add_offense(node, location: node.receiver.source_range, message: message)
|
43
50
|
end
|
44
51
|
|
45
52
|
def autocorrect(node)
|
46
53
|
return unless global_expectation?(node)
|
47
54
|
|
48
55
|
lambda do |corrector|
|
49
|
-
receiver = node.receiver.
|
56
|
+
receiver = node.receiver.source_range
|
50
57
|
|
51
58
|
if BLOCK_MATCHERS.include?(node.method_name)
|
52
59
|
corrector.insert_before(receiver, '_ { ')
|
@@ -60,12 +67,12 @@ module RuboCop
|
|
60
67
|
|
61
68
|
private
|
62
69
|
|
63
|
-
def
|
70
|
+
def preferred_receiver(node)
|
64
71
|
source = node.receiver.source
|
65
72
|
if BLOCK_MATCHERS.include?(node.method_name)
|
66
|
-
|
73
|
+
"_ { #{source} }"
|
67
74
|
else
|
68
|
-
|
75
|
+
"_(#{source})"
|
69
76
|
end
|
70
77
|
end
|
71
78
|
end
|
data/manual/cops_minitest.md
CHANGED
@@ -226,19 +226,21 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
|
|
226
226
|
--- | --- | --- | --- | ---
|
227
227
|
Enabled | Yes | Yes | 0.7 | -
|
228
228
|
|
229
|
-
This
|
229
|
+
This cop checks for deprecated global expectations
|
230
230
|
and autocorrects them to use expect format.
|
231
231
|
|
232
232
|
### Examples
|
233
233
|
|
234
234
|
```ruby
|
235
235
|
# bad
|
236
|
-
|
237
|
-
|
236
|
+
musts.must_equal expected_musts
|
237
|
+
wonts.wont_match expected_wonts
|
238
|
+
musts.must_raise TypeError
|
238
239
|
|
239
240
|
# good
|
240
|
-
_(
|
241
|
-
_(
|
241
|
+
_(musts).must_equal expected_musts
|
242
|
+
_(wonts).wont_match expected_wonts
|
243
|
+
_ { musts }.must_raise TypeError
|
242
244
|
```
|
243
245
|
|
244
246
|
## Minitest/RefuteEmpty
|
data/relnotes/v0.8.0.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#66](https://github.com/rubocop-hq/rubocop-minitest/issues/66): Support all expectations of `Minitest::Expectations` for `Minitest/GlobalExpectations` cop. ([@koic][])
|
4
|
+
|
5
|
+
### Bug fixes
|
6
|
+
|
7
|
+
* [#60](https://github.com/rubocop-hq/rubocop-minitest/issues/60): Fix `Minitest/GlobalExpectations` autocorrection for chained methods. ([@tejasbubane][])
|
8
|
+
* [#69](https://github.com/rubocop-hq/rubocop-minitest/pull/69): Fix a false negative for `Minitest/GlobalExpectations` cop when using a variable or a hash index for receiver. ([@koic][])
|
9
|
+
* [#71](https://github.com/rubocop-hq/rubocop-minitest/pull/71): Fix a false negative for `Minitest/AssertEqual` when an argument is enclosed in redundant parentheses. ([@koic][])
|
10
|
+
|
11
|
+
[@koic]: https://github.com/koic
|
12
|
+
[@tejasbubane]: https://github.com/tejasbubane
|
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.8.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: 2020-03-
|
13
|
+
date: 2020-03-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- relnotes/v0.6.1.md
|
111
111
|
- relnotes/v0.6.2.md
|
112
112
|
- relnotes/v0.7.0.md
|
113
|
+
- relnotes/v0.8.0.md
|
113
114
|
- rubocop-minitest.gemspec
|
114
115
|
- tasks/cops_documentation.rake
|
115
116
|
- tasks/cut_release.rake
|