rubocop-minitest 0.3.0 → 0.4.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 +14 -0
- data/Gemfile +1 -0
- data/README.md +2 -1
- data/config/default.yml +44 -19
- data/lib/rubocop-minitest.rb +0 -3
- data/lib/rubocop/cop/minitest/assert_equal.rb +57 -0
- data/lib/rubocop/cop/minitest/assert_instance_of.rb +60 -0
- data/lib/rubocop/cop/minitest/refute_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_instance_of.rb +60 -0
- data/lib/rubocop/cop/minitest/refute_respond_to.rb +51 -0
- data/lib/rubocop/cop/minitest_cops.rb +4 -0
- data/lib/rubocop/minitest/version.rb +1 -1
- data/manual/cops.md +4 -0
- data/manual/cops_minitest.md +99 -1
- data/relnotes/v0.1.0.md +7 -0
- data/relnotes/v0.2.0.md +9 -0
- data/relnotes/v0.2.1.md +5 -0
- data/relnotes/v0.3.0.md +16 -0
- data/relnotes/v0.4.0.md +14 -0
- data/tasks/cut_release.rake +60 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06679af4eeb82332ac490d8aceb5cd0668cb3686e1bf7f7d8fb83d1bc6d99f50'
|
4
|
+
data.tar.gz: f967a4cff6cfdc23182befb62fbc4363197213065acb21da6fc99e62d685951d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b2bbdefbd8de0346adb4b06884ab674ed88588bfaf8550ebcbadcd8f07be0199a0270c50ac15a9f36f607e157b3edde095db6e7caf3814cd8ff9ecc7350b9f3
|
7
|
+
data.tar.gz: 0f45beaa717b0d0135dd41462d372a794a66aea60e700f6cd942b79cd01a61f69914d45ad83ccad26ca95aa88b681d20f04b6b2b2e0a5278464399ef1a8ee47c
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.4.0 (2019-11-07)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#29](https://github.com/rubocop-hq/rubocop-minitest/pull/29): Add new `Minitest/RefuteRespondTo` cop. ([@herwinw][])
|
10
|
+
* [#31](https://github.com/rubocop-hq/rubocop-minitest/pull/31): Add new `Minitest/AssertEqual` cop. ([@herwinw][])
|
11
|
+
* [#34](https://github.com/rubocop-hq/rubocop-minitest/pull/34): Add new `Minitest/AssertInstanceOf` cop. ([@abhaynikam][])
|
12
|
+
* [#35](https://github.com/rubocop-hq/rubocop-minitest/pull/35): Add new `Minitest/RefuteInstanceOf` cop. ([@abhaynikam][])
|
13
|
+
|
14
|
+
### Bug fixes
|
15
|
+
|
16
|
+
* [#25](https://github.com/rubocop-hq/rubocop-minitest/issues/25): Add `Enabled: true` to `Minitest` department config to suppress `Warning: Minitest does not support Enabled parameter`. ([@koic][])
|
17
|
+
|
5
18
|
## 0.3.0 (2019-10-13)
|
6
19
|
|
7
20
|
### New features
|
@@ -42,3 +55,4 @@
|
|
42
55
|
[@duduribeiro]: https://github.com/duduribeiro
|
43
56
|
[@tejasbubane]: https://github.com/tejasbubane
|
44
57
|
[@abhaynikam]: https://github.com/abhaynikam
|
58
|
+
[@herwinw]: https://github.com/herwinw
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![CircleCI](https://circleci.com/gh/rubocop-hq/rubocop-minitest.svg?style=svg)](https://circleci.com/gh/rubocop-hq/rubocop-minitest)
|
5
5
|
|
6
6
|
A [RuboCop](https://github.com/rubocop-hq/rubocop) extension focused on enforcing Minitest best practices and coding conventions.
|
7
|
+
The library is based on the guidelines outlined in the community [Minitest Style Guide](https://minitest.rubystyle.guide).
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
@@ -61,7 +62,7 @@ end
|
|
61
62
|
|
62
63
|
All cops are located under
|
63
64
|
[`lib/rubocop/cop/minitest`](lib/rubocop/cop/minitest), and contain
|
64
|
-
examples/documentation.
|
65
|
+
examples/documentation. The documentation is published [here](https://docs.rubocop.org/projects/minitest).
|
65
66
|
|
66
67
|
In your `.rubocop.yml`, you may treat the Minitest cops just like any other
|
67
68
|
cop. For example:
|
data/config/default.yml
CHANGED
@@ -1,25 +1,38 @@
|
|
1
1
|
Minitest:
|
2
|
+
Enabled: true
|
2
3
|
Include:
|
3
4
|
- '**/test/**/*'
|
4
5
|
|
5
|
-
Minitest/AssertNil:
|
6
|
-
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)`.'
|
7
|
-
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-nil'
|
8
|
-
Enabled: true
|
9
|
-
VersionAdded: '0.1'
|
10
|
-
|
11
6
|
Minitest/AssertEmpty:
|
12
7
|
Description: 'This cop enforces the test to use `assert_empty` instead of using `assert(object.empty?)`.'
|
13
8
|
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-empty'
|
14
9
|
Enabled: true
|
15
10
|
VersionAdded: '0.2'
|
16
11
|
|
12
|
+
Minitest/AssertEqual:
|
13
|
+
Description: 'This cop enforces the test to use `assert_equal` instead of using `assert(expected == actual)`.'
|
14
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-equal-arguments-order'
|
15
|
+
Enabled: true
|
16
|
+
VersionAdded: '0.4'
|
17
|
+
|
17
18
|
Minitest/AssertIncludes:
|
18
19
|
Description: 'This cop enforces the test to use `assert_includes` instead of using `assert(collection.include?(object))`.'
|
19
20
|
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-includes'
|
20
21
|
Enabled: true
|
21
22
|
VersionAdded: '0.2'
|
22
23
|
|
24
|
+
Minitest/AssertInstanceOf:
|
25
|
+
Description: 'This cop enforces the test to use `assert_instance_of(Class, object)` over `assert(object.instance_of?(Class))`'
|
26
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of'
|
27
|
+
Enabled: true
|
28
|
+
VersionAdded: '0.4'
|
29
|
+
|
30
|
+
Minitest/AssertNil:
|
31
|
+
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)`.'
|
32
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-nil'
|
33
|
+
Enabled: true
|
34
|
+
VersionAdded: '0.1'
|
35
|
+
|
23
36
|
Minitest/AssertRespondTo:
|
24
37
|
Description: 'This cop enforces the test to use `assert_respond_to(object, :some_method)` over `assert(object.respond_to?(:some_method))`.'
|
25
38
|
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method'
|
@@ -32,21 +45,21 @@ Minitest/AssertTruthy:
|
|
32
45
|
Enabled: true
|
33
46
|
VersionAdded: '0.2'
|
34
47
|
|
48
|
+
Minitest/RefuteEmpty:
|
49
|
+
Description: 'This cop enforces to use `refute_empty` instead of using `refute(object.empty?)`.'
|
50
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-empty'
|
51
|
+
Enabled: true
|
52
|
+
VersionAdded: '0.3'
|
53
|
+
|
35
54
|
Minitest/RefuteEqual:
|
36
55
|
Description: 'Check if your test uses `refute_equal` instead of `assert(expected != object)` or `assert(! expected == object))`.'
|
37
56
|
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-equal'
|
38
57
|
Enabled: true
|
39
58
|
VersionAdded: '0.3'
|
40
59
|
|
41
|
-
Minitest/
|
42
|
-
Description: '
|
43
|
-
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-
|
44
|
-
Enabled: true
|
45
|
-
VersionAdded: '0.2'
|
46
|
-
|
47
|
-
Minitest/RefuteEmpty:
|
48
|
-
Description: 'This cop enforces to use `refute_empty` instead of using `refute(object.empty?)`.'
|
49
|
-
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-empty'
|
60
|
+
Minitest/RefuteFalse:
|
61
|
+
Description: 'Check if your test uses `refute(actual)` instead of `assert_equal(false, actual)`.'
|
62
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-false'
|
50
63
|
Enabled: true
|
51
64
|
VersionAdded: '0.3'
|
52
65
|
|
@@ -56,8 +69,20 @@ Minitest/RefuteIncludes:
|
|
56
69
|
Enabled: true
|
57
70
|
VersionAdded: '0.3'
|
58
71
|
|
59
|
-
Minitest/
|
60
|
-
Description: '
|
61
|
-
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-
|
72
|
+
Minitest/RefuteInstanceOf:
|
73
|
+
Description: 'This cop enforces the test to use `refute_instance_of(Class, object)` over `refute(object.instance_of?(Class))`.'
|
74
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of'
|
62
75
|
Enabled: true
|
63
|
-
VersionAdded: '0.
|
76
|
+
VersionAdded: '0.4'
|
77
|
+
|
78
|
+
Minitest/RefuteNil:
|
79
|
+
Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)`.'
|
80
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-nil'
|
81
|
+
Enabled: true
|
82
|
+
VersionAdded: '0.2'
|
83
|
+
|
84
|
+
Minitest/RefuteRespondTo:
|
85
|
+
Description: 'This cop enforces the test to use `refute_respond_to(object, :some_method)` over `refute(object.respond_to?(:some_method))`.'
|
86
|
+
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-respond-to'
|
87
|
+
Enabled: true
|
88
|
+
VersionAdded: '0.4'
|
data/lib/rubocop-minitest.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop enforces the use of `assert_equal(expected, actual)`
|
7
|
+
# over `assert(expected == actual)`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# assert("rubocop-minitest" == actual)
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# assert_equal("rubocop-minitest", actual)
|
15
|
+
#
|
16
|
+
class AssertEqual < Cop
|
17
|
+
MSG = 'Prefer using `assert_equal(%<preferred>s)` over ' \
|
18
|
+
'`assert(%<over>s)`.'
|
19
|
+
|
20
|
+
def_node_matcher :assert_equal, <<~PATTERN
|
21
|
+
(send nil? :assert $(send $_ :== $_) $...)
|
22
|
+
PATTERN
|
23
|
+
|
24
|
+
def on_send(node)
|
25
|
+
assert_equal(node) do
|
26
|
+
|first_receiver_arg, expected, actual, rest_receiver_arg|
|
27
|
+
|
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 |_receiver, expected, actual, rest_receiver_arg|
|
42
|
+
message = rest_receiver_arg.first
|
43
|
+
replacement = node_arguments(expected, actual, message)
|
44
|
+
corrector.replace(node.loc.expression, "assert_equal(#{replacement})")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def node_arguments(expected, actual, message)
|
52
|
+
[expected.source, actual.source, message&.source].compact.join(', ')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop enforces the test to use `assert_instance_of(Class, object)`
|
7
|
+
# over `assert(object.instance_of?(Class))`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# assert(object.instance_of?(Class))
|
12
|
+
# assert(object.instance_of?(Class), 'the message')
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# assert_instance_of(Class, object)
|
16
|
+
# assert_instance_of(Class, object, 'the message')
|
17
|
+
#
|
18
|
+
class AssertInstanceOf < Cop
|
19
|
+
MSG = 'Prefer using `assert_instance_of(%<arguments>s)` over ' \
|
20
|
+
'`assert(%<receiver>s)`.'
|
21
|
+
|
22
|
+
def_node_matcher :assert_with_instance_of, <<~PATTERN
|
23
|
+
(send nil? :assert $(send $_ :instance_of? $_) $...)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def on_send(node)
|
27
|
+
assert_with_instance_of(node) do
|
28
|
+
|first_receiver_arg, object, method, rest_args|
|
29
|
+
|
30
|
+
message = rest_args.first
|
31
|
+
arguments = node_arguments(object, method, message)
|
32
|
+
receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
|
33
|
+
|
34
|
+
offense_message = format(MSG, arguments: arguments, receiver: receiver)
|
35
|
+
|
36
|
+
add_offense(node, message: offense_message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def autocorrect(node)
|
41
|
+
lambda do |corrector|
|
42
|
+
assert_with_instance_of(node) do |_, object, method, rest_args|
|
43
|
+
message = rest_args.first
|
44
|
+
arguments = node_arguments(object, method, message)
|
45
|
+
|
46
|
+
replacement = "assert_instance_of(#{arguments})"
|
47
|
+
corrector.replace(node.loc.expression, replacement)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def node_arguments(object, method, message)
|
55
|
+
[method, object, message].compact.map(&:source).join(', ')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
6
|
# This cop enforces the use of `refute_equal(expected, object)`
|
7
|
-
# over `assert_equal(expected != actual)` or `assert(! expected
|
7
|
+
# over `assert_equal(expected != actual)` or `assert(! expected == actual)`.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop enforces the use of `refute_instance_of(Class, object)`
|
7
|
+
# over `refute(object.instance_of?(Class))`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# refute(object.instance_of?(Class))
|
12
|
+
# refute(object.instance_of?(Class), 'the message')
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# refute_instance_of(Class, object)
|
16
|
+
# refute_instance_of(Class, object, 'the message')
|
17
|
+
#
|
18
|
+
class RefuteInstanceOf < Cop
|
19
|
+
MSG = 'Prefer using `refute_instance_of(%<arguments>s)` over ' \
|
20
|
+
'`refute(%<receiver>s)`.'
|
21
|
+
|
22
|
+
def_node_matcher :refute_with_instance_of, <<~PATTERN
|
23
|
+
(send nil? :refute $(send $_ :instance_of? $_) $...)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def on_send(node)
|
27
|
+
refute_with_instance_of(node) do
|
28
|
+
|first_receiver_arg, object, method, rest_args|
|
29
|
+
|
30
|
+
message = rest_args.first
|
31
|
+
arguments = node_arguments(object, method, message)
|
32
|
+
receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
|
33
|
+
|
34
|
+
offense_message = format(MSG, arguments: arguments, receiver: receiver)
|
35
|
+
|
36
|
+
add_offense(node, message: offense_message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def autocorrect(node)
|
41
|
+
lambda do |corrector|
|
42
|
+
refute_with_instance_of(node) do |_, object, method, rest_args|
|
43
|
+
message = rest_args.first
|
44
|
+
arguments = node_arguments(object, method, message)
|
45
|
+
|
46
|
+
replacement = "refute_instance_of(#{arguments})"
|
47
|
+
corrector.replace(node.loc.expression, replacement)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def node_arguments(object, method, message)
|
55
|
+
[method, object, message].compact.map(&:source).join(', ')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# This cop enforces the test to use `refute_respond_to(object, :some_method)`
|
7
|
+
# over `refute(object.respond_to?(:some_method))`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# refute(object.respond_to?(:some_method))
|
12
|
+
# refute(object.respond_to?(:some_method), 'the message')
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# refute_respond_to(object, :some_method)
|
16
|
+
# refute_respond_to(object, :some_method, 'the message')
|
17
|
+
#
|
18
|
+
class RefuteRespondTo < Cop
|
19
|
+
MSG = 'Prefer using `refute_respond_to(%<preferred>s)` over ' \
|
20
|
+
'`refute(%<over>s)`.'
|
21
|
+
|
22
|
+
def_node_matcher :refute_with_respond_to, <<~PATTERN
|
23
|
+
(send nil? :refute $(send $_ :respond_to? $_) $...)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def on_send(node)
|
27
|
+
refute_with_respond_to(node) do |over, object, method, rest_args|
|
28
|
+
custom_message = rest_args.first
|
29
|
+
preferred = [object, method, custom_message]
|
30
|
+
.compact.map(&:source).join(', ')
|
31
|
+
over = [over, custom_message].compact.map(&:source).join(', ')
|
32
|
+
message = format(MSG, preferred: preferred, over: over)
|
33
|
+
add_offense(node, message: message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def autocorrect(node)
|
38
|
+
lambda do |corrector|
|
39
|
+
refute_with_respond_to(node) do |_, object, method, rest_args|
|
40
|
+
custom_message = rest_args.first
|
41
|
+
preferred = [object, method, custom_message]
|
42
|
+
.compact.map(&:source).join(', ')
|
43
|
+
replacement = "refute_respond_to(#{preferred})"
|
44
|
+
corrector.replace(node.loc.expression, replacement)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'minitest/assert_empty'
|
4
|
+
require_relative 'minitest/assert_equal'
|
4
5
|
require_relative 'minitest/assert_nil'
|
5
6
|
require_relative 'minitest/assert_includes'
|
7
|
+
require_relative 'minitest/assert_instance_of'
|
6
8
|
require_relative 'minitest/assert_respond_to'
|
7
9
|
require_relative 'minitest/assert_truthy'
|
8
10
|
require_relative 'minitest/refute_empty'
|
@@ -10,3 +12,5 @@ require_relative 'minitest/refute_false'
|
|
10
12
|
require_relative 'minitest/refute_equal'
|
11
13
|
require_relative 'minitest/refute_nil'
|
12
14
|
require_relative 'minitest/refute_includes'
|
15
|
+
require_relative 'minitest/refute_instance_of'
|
16
|
+
require_relative 'minitest/refute_respond_to'
|
data/manual/cops.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
#### Department [Minitest](cops_minitest.md)
|
3
3
|
|
4
4
|
* [Minitest/AssertEmpty](cops_minitest.md#minitestassertempty)
|
5
|
+
* [Minitest/AssertEqual](cops_minitest.md#minitestassertequal)
|
5
6
|
* [Minitest/AssertIncludes](cops_minitest.md#minitestassertincludes)
|
7
|
+
* [Minitest/AssertInstanceOf](cops_minitest.md#minitestassertinstanceof)
|
6
8
|
* [Minitest/AssertNil](cops_minitest.md#minitestassertnil)
|
7
9
|
* [Minitest/AssertRespondTo](cops_minitest.md#minitestassertrespondto)
|
8
10
|
* [Minitest/AssertTruthy](cops_minitest.md#minitestasserttruthy)
|
@@ -10,6 +12,8 @@
|
|
10
12
|
* [Minitest/RefuteEqual](cops_minitest.md#minitestrefuteequal)
|
11
13
|
* [Minitest/RefuteFalse](cops_minitest.md#minitestrefutefalse)
|
12
14
|
* [Minitest/RefuteIncludes](cops_minitest.md#minitestrefuteincludes)
|
15
|
+
* [Minitest/RefuteInstanceOf](cops_minitest.md#minitestrefuteinstanceof)
|
13
16
|
* [Minitest/RefuteNil](cops_minitest.md#minitestrefutenil)
|
17
|
+
* [Minitest/RefuteRespondTo](cops_minitest.md#minitestrefuterespondto)
|
14
18
|
|
15
19
|
<!-- END_COP_LIST -->
|
data/manual/cops_minitest.md
CHANGED
@@ -25,6 +25,29 @@ assert_empty(object, 'the message')
|
|
25
25
|
|
26
26
|
* [https://github.com/rubocop-hq/minitest-style-guide#assert-empty](https://github.com/rubocop-hq/minitest-style-guide#assert-empty)
|
27
27
|
|
28
|
+
## Minitest/AssertEqual
|
29
|
+
|
30
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
31
|
+
--- | --- | --- | --- | ---
|
32
|
+
Enabled | Yes | Yes | 0.4 | -
|
33
|
+
|
34
|
+
This cop enforces the use of `assert_equal(expected, actual)`
|
35
|
+
over `assert(expected == actual)`.
|
36
|
+
|
37
|
+
### Examples
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# bad
|
41
|
+
assert("rubocop-minitest" == actual)
|
42
|
+
|
43
|
+
# good
|
44
|
+
assert_equal("rubocop-minitest", actual)
|
45
|
+
```
|
46
|
+
|
47
|
+
### References
|
48
|
+
|
49
|
+
* [https://github.com/rubocop-hq/minitest-style-guide#assert-equal-arguments-order](https://github.com/rubocop-hq/minitest-style-guide#assert-equal-arguments-order)
|
50
|
+
|
28
51
|
## Minitest/AssertIncludes
|
29
52
|
|
30
53
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
@@ -50,6 +73,31 @@ assert_includes(collection, object, 'the message')
|
|
50
73
|
|
51
74
|
* [https://github.com/rubocop-hq/minitest-style-guide#assert-includes](https://github.com/rubocop-hq/minitest-style-guide#assert-includes)
|
52
75
|
|
76
|
+
## Minitest/AssertInstanceOf
|
77
|
+
|
78
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
79
|
+
--- | --- | --- | --- | ---
|
80
|
+
Enabled | Yes | Yes | 0.4 | -
|
81
|
+
|
82
|
+
This cop enforces the test to use `assert_instance_of(Class, object)`
|
83
|
+
over `assert(object.instance_of?(Class))`.
|
84
|
+
|
85
|
+
### Examples
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# bad
|
89
|
+
assert(object.instance_of?(Class))
|
90
|
+
assert(object.instance_of?(Class), 'the message')
|
91
|
+
|
92
|
+
# good
|
93
|
+
assert_instance_of(Class, object)
|
94
|
+
assert_instance_of(Class, object, 'the message')
|
95
|
+
```
|
96
|
+
|
97
|
+
### References
|
98
|
+
|
99
|
+
* [https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of](https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of)
|
100
|
+
|
53
101
|
## Minitest/AssertNil
|
54
102
|
|
55
103
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
@@ -157,7 +205,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
|
|
157
205
|
Enabled | Yes | Yes | 0.3 | -
|
158
206
|
|
159
207
|
This cop enforces the use of `refute_equal(expected, object)`
|
160
|
-
over `assert_equal(expected != actual)` or `assert(! expected
|
208
|
+
over `assert_equal(expected != actual)` or `assert(! expected == actual)`.
|
161
209
|
|
162
210
|
### Examples
|
163
211
|
|
@@ -224,6 +272,31 @@ refute_includes(collection, object, 'the message')
|
|
224
272
|
|
225
273
|
* [https://github.com/rubocop-hq/minitest-style-guide#refute-includes](https://github.com/rubocop-hq/minitest-style-guide#refute-includes)
|
226
274
|
|
275
|
+
## Minitest/RefuteInstanceOf
|
276
|
+
|
277
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
278
|
+
--- | --- | --- | --- | ---
|
279
|
+
Enabled | Yes | Yes | 0.4 | -
|
280
|
+
|
281
|
+
This cop enforces the use of `refute_instance_of(Class, object)`
|
282
|
+
over `refute(object.instance_of?(Class))`.
|
283
|
+
|
284
|
+
### Examples
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
# bad
|
288
|
+
refute(object.instance_of?(Class))
|
289
|
+
refute(object.instance_of?(Class), 'the message')
|
290
|
+
|
291
|
+
# good
|
292
|
+
refute_instance_of(Class, object)
|
293
|
+
refute_instance_of(Class, object, 'the message')
|
294
|
+
```
|
295
|
+
|
296
|
+
### References
|
297
|
+
|
298
|
+
* [https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of](https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of)
|
299
|
+
|
227
300
|
## Minitest/RefuteNil
|
228
301
|
|
229
302
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
@@ -248,3 +321,28 @@ refute_nil(actual, 'the message')
|
|
248
321
|
### References
|
249
322
|
|
250
323
|
* [https://github.com/rubocop-hq/minitest-style-guide#refute-nil](https://github.com/rubocop-hq/minitest-style-guide#refute-nil)
|
324
|
+
|
325
|
+
## Minitest/RefuteRespondTo
|
326
|
+
|
327
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
328
|
+
--- | --- | --- | --- | ---
|
329
|
+
Enabled | Yes | Yes | 0.4 | -
|
330
|
+
|
331
|
+
This cop enforces the test to use `refute_respond_to(object, :some_method)`
|
332
|
+
over `refute(object.respond_to?(:some_method))`.
|
333
|
+
|
334
|
+
### Examples
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
# bad
|
338
|
+
refute(object.respond_to?(:some_method))
|
339
|
+
refute(object.respond_to?(:some_method), 'the message')
|
340
|
+
|
341
|
+
# good
|
342
|
+
refute_respond_to(object, :some_method)
|
343
|
+
refute_respond_to(object, :some_method, 'the message')
|
344
|
+
```
|
345
|
+
|
346
|
+
### References
|
347
|
+
|
348
|
+
* [https://github.com/rubocop-hq/minitest-style-guide#refute-respond-to](https://github.com/rubocop-hq/minitest-style-guide#refute-respond-to)
|
data/relnotes/v0.1.0.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* Create RuboCop Minitest gem. ([@koic][])
|
4
|
+
* [#6](https://github.com/rubocop-hq/rubocop-minitest/pull/6): Add new `Minitest/AssertNil` cop. ([@duduribeiro ][])
|
5
|
+
|
6
|
+
[@koic]: https://github.com/koic
|
7
|
+
[@duduribeiro]: https://github.com/duduribeiro
|
data/relnotes/v0.2.0.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#11](https://github.com/rubocop-hq/rubocop-minitest/pull/11): Add new `Minitest/RefuteNil` cop. ([@tejasbubane ][])
|
4
|
+
* [#8](https://github.com/rubocop-hq/rubocop-minitest/pull/8): Add new `Minitest/AssertTruthy` cop. ([@abhaynikam ][])
|
5
|
+
* [#9](https://github.com/rubocop-hq/rubocop-minitest/pull/9): Add new `Minitest/AssertIncludes` cop. ([@abhaynikam ][])
|
6
|
+
* [#10](https://github.com/rubocop-hq/rubocop-minitest/pull/10): Add new `Minitest/AssertEmpty` cop. ([@abhaynikam ][])
|
7
|
+
|
8
|
+
[@tejasbubane]: https://github.com/tejasbubane
|
9
|
+
[@abhaynikam]: https://github.com/abhaynikam
|
data/relnotes/v0.2.1.md
ADDED
data/relnotes/v0.3.0.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## 0.3.0 (2019-10-13)
|
2
|
+
|
3
|
+
### New features
|
4
|
+
|
5
|
+
* [#15](https://github.com/rubocop-hq/rubocop-minitest/pull/15): Add new `Minitest/RefuteIncludes` cop. ([@abhaynikam][])
|
6
|
+
* [#18](https://github.com/rubocop-hq/rubocop-minitest/pull/18): Add new `Minitest/RefuteFalse` cop. ([@duduribeiro][])
|
7
|
+
* [#20](https://github.com/rubocop-hq/rubocop-minitest/pull/20): Add new `Minitest/RefuteEmpty` cop. ([@abhaynikam][])
|
8
|
+
* [#21](https://github.com/rubocop-hq/rubocop-minitest/pull/21): Add new `Minitest/RefuteEqual` cop. ([@duduribeiro][])
|
9
|
+
* [#27](https://github.com/rubocop-hq/rubocop-minitest/pull/27): Add new `Minitest/AssertRespondTo` cop. ([@duduribeiro][])
|
10
|
+
|
11
|
+
### Bug fixes
|
12
|
+
|
13
|
+
* [#19](https://github.com/rubocop-hq/rubocop-minitest/pull/19): Fix a false negative for `Minitest/AssertIncludes` when using `include` method in arguments of `assert` method. ([@abhaynikam][])
|
14
|
+
|
15
|
+
[@abhaynikam]: https://github.com/abhaynikam
|
16
|
+
[@duduribeiro]: https://github.com/duduribeiro
|
data/relnotes/v0.4.0.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#29](https://github.com/rubocop-hq/rubocop-minitest/pull/29): Add new `Minitest/RefuteRespondTo` cop. ([@herwinw][])
|
4
|
+
* [#31](https://github.com/rubocop-hq/rubocop-minitest/pull/31): Add new `Minitest/AssertEqual` cop. ([@herwinw][])
|
5
|
+
* [#34](https://github.com/rubocop-hq/rubocop-minitest/pull/34): Add new `Minitest/AssertInstanceOf` cop. ([@abhaynikam][])
|
6
|
+
* [#35](https://github.com/rubocop-hq/rubocop-minitest/pull/35): Add new `Minitest/RefuteInstanceOf` cop. ([@abhaynikam][])
|
7
|
+
|
8
|
+
### Bug fixes
|
9
|
+
|
10
|
+
* [#25](https://github.com/rubocop-hq/rubocop-minitest/issues/25): Add `Enabled: true` to `Minitest` department config to suppress `Warning: Minitest does not support Enabled parameter`. ([@koic][])
|
11
|
+
|
12
|
+
[@herwinw]: https://github.com/herwinw
|
13
|
+
[@abhaynikam]: https://github.com/abhaynikam
|
14
|
+
[@koic]: https://github.com/koic
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bump'
|
4
|
+
|
5
|
+
namespace :cut_release do
|
6
|
+
%w[major minor patch pre].each do |release_type|
|
7
|
+
desc "Cut a new #{release_type} release, create release notes " \
|
8
|
+
'and update documents.'
|
9
|
+
task release_type do
|
10
|
+
run(release_type)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_header_to_changelog(version)
|
15
|
+
changelog = File.read('CHANGELOG.md')
|
16
|
+
head, tail = changelog.split("## master (unreleased)\n\n", 2)
|
17
|
+
|
18
|
+
File.open('CHANGELOG.md', 'w') do |f|
|
19
|
+
f << head
|
20
|
+
f << "## master (unreleased)\n\n"
|
21
|
+
f << "## #{version} (#{Time.now.strftime('%F')})\n\n"
|
22
|
+
f << tail
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_release_notes(version)
|
27
|
+
release_notes = new_version_changes.strip
|
28
|
+
contributor_links = user_links(release_notes)
|
29
|
+
|
30
|
+
File.open("relnotes/v#{version}.md", 'w') do |file|
|
31
|
+
file << release_notes
|
32
|
+
file << "\n\n"
|
33
|
+
file << contributor_links
|
34
|
+
file << "\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_version_changes
|
39
|
+
changelog = File.read('CHANGELOG.md')
|
40
|
+
_, _, new_changes, _older_changes = changelog.split(/^## .*$/, 4)
|
41
|
+
new_changes
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_links(text)
|
45
|
+
names = text.scan(/\[@(\S+)\]\[\]/).map(&:first).uniq
|
46
|
+
names.map { |name| "[@#{name}]: https://github.com/#{name}" }
|
47
|
+
.join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def run(release_type)
|
51
|
+
old_version = Bump::Bump.current
|
52
|
+
Bump::Bump.run(release_type, commit: false, bundle: false, tag: false)
|
53
|
+
new_version = Bump::Bump.current
|
54
|
+
|
55
|
+
add_header_to_changelog(new_version)
|
56
|
+
create_release_notes(new_version)
|
57
|
+
|
58
|
+
puts "Changed version from #{old_version} to #{new_version}."
|
59
|
+
end
|
60
|
+
end
|
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.4.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: 2019-
|
13
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -67,7 +67,9 @@ files:
|
|
67
67
|
- config/default.yml
|
68
68
|
- lib/rubocop-minitest.rb
|
69
69
|
- lib/rubocop/cop/minitest/assert_empty.rb
|
70
|
+
- lib/rubocop/cop/minitest/assert_equal.rb
|
70
71
|
- lib/rubocop/cop/minitest/assert_includes.rb
|
72
|
+
- lib/rubocop/cop/minitest/assert_instance_of.rb
|
71
73
|
- lib/rubocop/cop/minitest/assert_nil.rb
|
72
74
|
- lib/rubocop/cop/minitest/assert_respond_to.rb
|
73
75
|
- lib/rubocop/cop/minitest/assert_truthy.rb
|
@@ -75,7 +77,9 @@ files:
|
|
75
77
|
- lib/rubocop/cop/minitest/refute_equal.rb
|
76
78
|
- lib/rubocop/cop/minitest/refute_false.rb
|
77
79
|
- lib/rubocop/cop/minitest/refute_includes.rb
|
80
|
+
- lib/rubocop/cop/minitest/refute_instance_of.rb
|
78
81
|
- lib/rubocop/cop/minitest/refute_nil.rb
|
82
|
+
- lib/rubocop/cop/minitest/refute_respond_to.rb
|
79
83
|
- lib/rubocop/cop/minitest_cops.rb
|
80
84
|
- lib/rubocop/minitest.rb
|
81
85
|
- lib/rubocop/minitest/inject.rb
|
@@ -87,8 +91,14 @@ files:
|
|
87
91
|
- manual/usage.md
|
88
92
|
- mkdocs.yml
|
89
93
|
- readthedocs.yml
|
94
|
+
- relnotes/v0.1.0.md
|
95
|
+
- relnotes/v0.2.0.md
|
96
|
+
- relnotes/v0.2.1.md
|
97
|
+
- relnotes/v0.3.0.md
|
98
|
+
- relnotes/v0.4.0.md
|
90
99
|
- rubocop-minitest.gemspec
|
91
100
|
- tasks/cops_documentation.rake
|
101
|
+
- tasks/cut_release.rake
|
92
102
|
homepage:
|
93
103
|
licenses:
|
94
104
|
- MIT
|