rubocop-minitest 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc2eabe582388a8716653ef64d84833b48547f2c0e84fd666c36ab59b773abdc
4
- data.tar.gz: 726cd0a1cc2f11eee03f49278408b9eda29308d74641cdc8a562f84c063e4e8c
3
+ metadata.gz: 6971c190fb9bb75de58013b61826afebf8ff0213d6b4a82e215704baa655014d
4
+ data.tar.gz: 2a1abf652db222f834a3e400240d99e01edca9539de7024220598e03e75cea26
5
5
  SHA512:
6
- metadata.gz: 60bec75d6fab0181c7f1ee5e664ca0a9dda0d8ba7d9a54d184a7f4573633e10fccef93719da3dead41c5919862f67aa0b66eb92f1dc933759c240e093ee93bd0
7
- data.tar.gz: 28d6e3f708ce291589ff8e2b74a12792777dbc39e244309951ba21e1ffdd59ac982fed3f52af148acca2b8a96bc8f0158711c3e99f893f09d26ef74beb743d2e
6
+ metadata.gz: 8bc4d5b65791a48ffc5cfe2256b7496d6b99d750b331640bd8e2406c0cc030af2a9daf4a32671c81727a200ce6ba0d7601ab5752b84887d239f35204a8974a0d
7
+ data.tar.gz: 0b58903c1bf5ab77e2a5d27c0b318d4d917ab78bbebe9a42f5f8432e2116bce9ceec6c5efc09dc640cd6efc1399fab17ed65422ef0fbce6de3ab82fb99d2c84c
@@ -0,0 +1,6 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: bbatsov
4
+ patreon: bbatsov
5
+ open_collective: rubocop
6
+ custom: https://www.paypal.me/bbatsov
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.3.0 (2019-10-13)
6
+
7
+ ### New features
8
+
9
+ * [#15](https://github.com/rubocop-hq/rubocop-minitest/pull/15): Add new `Minitest/RefuteIncludes` cop. ([@abhaynikam][])
10
+ * [#18](https://github.com/rubocop-hq/rubocop-minitest/pull/18): Add new `Minitest/RefuteFalse` cop. ([@duduribeiro][])
11
+ * [#20](https://github.com/rubocop-hq/rubocop-minitest/pull/20): Add new `Minitest/RefuteEmpty` cop. ([@abhaynikam][])
12
+ * [#21](https://github.com/rubocop-hq/rubocop-minitest/pull/21): Add new `Minitest/RefuteEqual` cop. ([@duduribeiro][])
13
+ * [#27](https://github.com/rubocop-hq/rubocop-minitest/pull/27): Add new `Minitest/AssertRespondTo` cop. ([@duduribeiro][])
14
+
15
+ ### Bug fixes
16
+
17
+ * [#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][])
18
+
5
19
  ## 0.2.1 (2019-09-24)
6
20
 
7
21
  ### Bug fixes
@@ -3,31 +3,61 @@ Minitest:
3
3
  - '**/test/**/*'
4
4
 
5
5
  Minitest/AssertNil:
6
- Description: 'Check if your test uses `assert_nil` instead of `assert_equal(nil, something)`.'
6
+ Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)`.'
7
7
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-nil'
8
8
  Enabled: true
9
9
  VersionAdded: '0.1'
10
10
 
11
11
  Minitest/AssertEmpty:
12
- Description: 'Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.'
12
+ Description: 'This cop enforces the test to use `assert_empty` instead of using `assert(object.empty?)`.'
13
13
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-empty'
14
14
  Enabled: true
15
15
  VersionAdded: '0.2'
16
16
 
17
17
  Minitest/AssertIncludes:
18
- Description: 'Check if your test uses `assert_includes` instead of `assert(collection.includes?(actual))`.'
18
+ Description: 'This cop enforces the test to use `assert_includes` instead of using `assert(collection.include?(object))`.'
19
19
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-includes'
20
20
  Enabled: true
21
21
  VersionAdded: '0.2'
22
22
 
23
+ Minitest/AssertRespondTo:
24
+ Description: 'This cop enforces the test to use `assert_respond_to(object, :some_method)` over `assert(object.respond_to?(:some_method))`.'
25
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method'
26
+ Enabled: true
27
+ VersionAdded: '0.3'
28
+
23
29
  Minitest/AssertTruthy:
24
- Description: 'Check if your test uses `assert(actual)` instead of `assert_equal(true, actual)`.'
30
+ Description: 'This cop enforces the test to use `assert(actual)` instead of using `assert_equal(true, actual)`.'
25
31
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-truthy'
26
32
  Enabled: true
27
33
  VersionAdded: '0.2'
28
34
 
35
+ Minitest/RefuteEqual:
36
+ Description: 'Check if your test uses `refute_equal` instead of `assert(expected != object)` or `assert(! expected == object))`.'
37
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-equal'
38
+ Enabled: true
39
+ VersionAdded: '0.3'
40
+
29
41
  Minitest/RefuteNil:
30
- Description: 'Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.'
42
+ Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)`.'
31
43
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-nil'
32
44
  Enabled: true
33
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'
50
+ Enabled: true
51
+ VersionAdded: '0.3'
52
+
53
+ Minitest/RefuteIncludes:
54
+ Description: 'This cop enforces the test to use `refute_includes` instead of using `refute(collection.include?(object))`.'
55
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-includes'
56
+ Enabled: true
57
+ VersionAdded: '0.3'
58
+
59
+ Minitest/RefuteFalse:
60
+ Description: 'Check if your test uses `refute(actual)` instead of `assert_equal(false, actual)`.'
61
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-false'
62
+ Enabled: true
63
+ VersionAdded: '0.3'
@@ -3,16 +3,17 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
- # Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.
6
+ # This cop enforces the test to use `assert_empty`
7
+ # instead of using `assert(object.empty?)`.
7
8
  #
8
9
  # @example
9
10
  # # bad
10
- # assert(actual.empty?)
11
- # assert(actual.empty?, 'the message')
11
+ # assert(object.empty?)
12
+ # assert(object.empty?, 'the message')
12
13
  #
13
14
  # # good
14
- # assert_empty(actual)
15
- # assert_empty(actual, 'the message')
15
+ # assert_empty(object)
16
+ # assert_empty(object, 'the message')
16
17
  #
17
18
  class AssertEmpty < Cop
18
19
  MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
@@ -3,24 +3,24 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
- # Check if your test uses `assert_includes`
7
- # instead of `assert(collection.includes?(actual))`.
6
+ # This cop enforces the test to use `assert_includes`
7
+ # instead of using `assert(collection.include?(object))`.
8
8
  #
9
9
  # @example
10
10
  # # bad
11
- # assert(collection.includes?(actual))
12
- # assert(collection.includes?(actual), 'the message')
11
+ # assert(collection.include?(object))
12
+ # assert(collection.include?(object), 'the message')
13
13
  #
14
14
  # # good
15
- # assert_includes(collection, actual)
16
- # assert_includes(collection, actual, 'the message')
15
+ # assert_includes(collection, object)
16
+ # assert_includes(collection, object, 'the message')
17
17
  #
18
18
  class AssertIncludes < Cop
19
19
  MSG = 'Prefer using `assert_includes(%<arguments>s)` over ' \
20
20
  '`assert(%<receiver>s)`.'
21
21
 
22
22
  def_node_matcher :assert_with_includes, <<~PATTERN
23
- (send nil? :assert $(send $_ :includes? $_) $...)
23
+ (send nil? :assert $(send $_ :include? $_) $...)
24
24
  PATTERN
25
25
 
26
26
  def on_send(node)
@@ -3,7 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
- # Check if your test uses `assert_nil` instead of `assert_equal(nil, something)`.
6
+ # This cop enforces the test to use `assert_nil`
7
+ # instead of using `assert_equal(nil, something)`.
7
8
  #
8
9
  # @example
9
10
  # # bad
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces the use of `assert_respond_to(object, :some_method)`
7
+ # over `assert(object.respond_to?(:some_method))`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert(object.respond_to?(:some_method))
12
+ # assert(object.respond_to?(:some_method), 'the message')
13
+ #
14
+ # # good
15
+ # assert_respond_to(object, :some_method)
16
+ # assert_respond_to(object, :some_method, 'the message')
17
+ #
18
+ class AssertRespondTo < Cop
19
+ MSG = 'Prefer using `assert_respond_to(%<preferred>s)` over ' \
20
+ '`assert(%<over>s)`.'
21
+
22
+ def_node_matcher :assert_with_respond_to, <<~PATTERN
23
+ (send nil? :assert $(send $_ :respond_to? $_) $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ assert_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
+ assert_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 = "assert_respond_to(#{preferred})"
44
+ corrector.replace(node.loc.expression, replacement)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -3,8 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
- # Check if your test uses `assert(actual)`
7
- # instead of `assert_equal(true, actual)`.
6
+ # This cop enforces the test to use `assert(actual)`
7
+ # instead of using `assert_equal(true, actual)`.
8
8
  #
9
9
  # @example
10
10
  # # bad
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces to use `refute_empty` instead of
7
+ # using `refute(object.empty?)`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # refute(object.empty?)
12
+ # refute(object.empty?, 'the message')
13
+ #
14
+ # # good
15
+ # refute_empty(object)
16
+ # refute_empty(object, 'the message')
17
+ #
18
+ class RefuteEmpty < Cop
19
+ MSG = 'Prefer using `refute_empty(%<arguments>s)` over ' \
20
+ '`refute(%<receiver>s)`.'
21
+
22
+ def_node_matcher :refute_with_empty, <<~PATTERN
23
+ (send nil? :refute $(send $_ :empty?) $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ refute_with_empty(node) do |first_receiver_arg, object, rest_receiver_arg|
28
+ message = rest_receiver_arg.first
29
+
30
+ arguments = [object.source, message&.source].compact.join(', ')
31
+ receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
32
+
33
+ offense_message = format(MSG, arguments: arguments, receiver: receiver)
34
+ add_offense(node, message: offense_message)
35
+ end
36
+ end
37
+
38
+ def autocorrect(node)
39
+ lambda do |corrector|
40
+ refute_with_empty(node) do |_first_receiver_arg, object, rest_receiver_arg|
41
+ message = rest_receiver_arg.first
42
+
43
+ replacement = [object.source, message&.source].compact.join(', ')
44
+ corrector.replace(node.loc.expression, "refute_empty(#{replacement})")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces the use of `refute_equal(expected, object)`
7
+ # over `assert_equal(expected != actual)` or `assert(! expected -= actual)`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert("rubocop-minitest" != actual)
12
+ # assert(! "rubocop-minitest" == actual)
13
+ #
14
+ # # good
15
+ # refute_equal("rubocop-minitest", actual)
16
+ #
17
+ class RefuteEqual < Cop
18
+ MSG = 'Prefer using `refute_equal(%<preferred>s)` over ' \
19
+ '`assert(%<over>s)`.'
20
+
21
+ def_node_matcher :assert_not_equal, <<~PATTERN
22
+ (send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... )
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ preferred, over = process_not_equal(node)
27
+ return unless preferred && over
28
+
29
+ message = format(MSG, preferred: preferred, over: over)
30
+ add_offense(node, message: message)
31
+ end
32
+
33
+ def autocorrect(node)
34
+ lambda do |corrector|
35
+ assert_not_equal(node) do |_, first_arg, second_arg, rest_args|
36
+ autocorrect_node(node, corrector, first_arg, second_arg, rest_args)
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def autocorrect_node(node, corrector, first_arg, second_arg, rest_args)
44
+ custom_message = rest_args.first
45
+ replacement = preferred_usage(first_arg, second_arg, custom_message)
46
+ corrector.replace(node.loc.expression, "refute_equal(#{replacement})")
47
+ end
48
+
49
+ def preferred_usage(first_arg, second_arg, custom_message = nil)
50
+ [first_arg, second_arg, custom_message]
51
+ .compact.map(&:source).join(', ')
52
+ end
53
+
54
+ def original_usage(first_part, custom_message)
55
+ [first_part, custom_message].compact.join(', ')
56
+ end
57
+
58
+ def process_not_equal(node)
59
+ assert_not_equal(node) do |over, first_arg, second_arg, rest_args|
60
+ custom_message = rest_args.first
61
+ preferred = preferred_usage(first_arg, second_arg, custom_message)
62
+ over = original_usage(over.source, custom_message&.source)
63
+ return [preferred, over]
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces the use of `refute(object)`
7
+ # over `assert_equal(false, object)`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert_equal(false, actual)
12
+ # assert_equal(false, actual, 'the message')
13
+ #
14
+ # # good
15
+ # refute(actual)
16
+ # refute(actual, 'the message')
17
+ #
18
+ class RefuteFalse < Cop
19
+ MSG = 'Prefer using `refute(%<arguments>s)` over ' \
20
+ '`assert_equal(false, %<arguments>s)`.'
21
+
22
+ def_node_matcher :assert_equal_with_false, <<~PATTERN
23
+ (send nil? :assert_equal false $_ $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ assert_equal_with_false(node) do |actual, rest_receiver_arg|
28
+ message = rest_receiver_arg.first
29
+
30
+ arguments = [actual.source, message&.source].compact.join(', ')
31
+
32
+ add_offense(node, message: format(MSG, arguments: arguments))
33
+ end
34
+ end
35
+
36
+ def autocorrect(node)
37
+ lambda do |corrector|
38
+ arguments = node.arguments.reject(&:false_type?)
39
+ replacement = arguments.map(&:source).join(', ')
40
+ corrector.replace(node.loc.expression, "refute(#{replacement})")
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ 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 `refute_includes`
7
+ # instead of using `refute(collection.include?(object))`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # refute(collection.include?(object))
12
+ # refute(collection.include?(object), 'the message')
13
+ #
14
+ # # good
15
+ # refute_includes(collection, object)
16
+ # refute_includes(collection, object, 'the message')
17
+ #
18
+ class RefuteIncludes < Cop
19
+ MSG = 'Prefer using `refute_includes(%<arguments>s)` over ' \
20
+ '`refute(%<receiver>s)`.'
21
+
22
+ def_node_matcher :refute_with_includes, <<~PATTERN
23
+ (send nil? :refute $(send $_ :include? $_) $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ refute_with_includes(node) do
28
+ |first_receiver_arg, collection, object, rest_receiver_arg|
29
+
30
+ message = rest_receiver_arg.first
31
+ arguments = node_arguments(collection, object, 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_includes(node) do
43
+ |_receiver, collection, object, rest_receiver_arg|
44
+
45
+ message = rest_receiver_arg.first
46
+ replacement = node_arguments(collection, object, message)
47
+ corrector.replace(node.loc.expression, "refute_includes(#{replacement})")
48
+ end
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def node_arguments(collection, object, message)
55
+ [collection.source, object.source, message&.source].compact.join(', ')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -3,7 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
- # Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.
6
+ # This cop enforces the test to use `refute_nil`
7
+ # instead of using `refute_equal(nil, something)`.
7
8
  #
8
9
  # @example
9
10
  # # bad
@@ -3,5 +3,10 @@
3
3
  require_relative 'minitest/assert_empty'
4
4
  require_relative 'minitest/assert_nil'
5
5
  require_relative 'minitest/assert_includes'
6
+ require_relative 'minitest/assert_respond_to'
6
7
  require_relative 'minitest/assert_truthy'
8
+ require_relative 'minitest/refute_empty'
9
+ require_relative 'minitest/refute_false'
10
+ require_relative 'minitest/refute_equal'
7
11
  require_relative 'minitest/refute_nil'
12
+ require_relative 'minitest/refute_includes'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Minitest
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -4,7 +4,12 @@
4
4
  * [Minitest/AssertEmpty](cops_minitest.md#minitestassertempty)
5
5
  * [Minitest/AssertIncludes](cops_minitest.md#minitestassertincludes)
6
6
  * [Minitest/AssertNil](cops_minitest.md#minitestassertnil)
7
+ * [Minitest/AssertRespondTo](cops_minitest.md#minitestassertrespondto)
7
8
  * [Minitest/AssertTruthy](cops_minitest.md#minitestasserttruthy)
9
+ * [Minitest/RefuteEmpty](cops_minitest.md#minitestrefuteempty)
10
+ * [Minitest/RefuteEqual](cops_minitest.md#minitestrefuteequal)
11
+ * [Minitest/RefuteFalse](cops_minitest.md#minitestrefutefalse)
12
+ * [Minitest/RefuteIncludes](cops_minitest.md#minitestrefuteincludes)
8
13
  * [Minitest/RefuteNil](cops_minitest.md#minitestrefutenil)
9
14
 
10
15
  <!-- END_COP_LIST -->
@@ -6,18 +6,19 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
6
6
  --- | --- | --- | --- | ---
7
7
  Enabled | Yes | Yes | 0.2 | -
8
8
 
9
- Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.
9
+ This cop enforces the test to use `assert_empty`
10
+ instead of using `assert(object.empty?)`.
10
11
 
11
12
  ### Examples
12
13
 
13
14
  ```ruby
14
15
  # bad
15
- assert(actual.empty?)
16
- assert(actual.empty?, 'the message')
16
+ assert(object.empty?)
17
+ assert(object.empty?, 'the message')
17
18
 
18
19
  # good
19
- assert_empty(actual)
20
- assert_empty(actual, 'the message')
20
+ assert_empty(object)
21
+ assert_empty(object, 'the message')
21
22
  ```
22
23
 
23
24
  ### References
@@ -30,19 +31,19 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
30
31
  --- | --- | --- | --- | ---
31
32
  Enabled | Yes | Yes | 0.2 | -
32
33
 
33
- Check if your test uses `assert_includes`
34
- instead of `assert(collection.includes?(actual))`.
34
+ This cop enforces the test to use `assert_includes`
35
+ instead of using `assert(collection.include?(object))`.
35
36
 
36
37
  ### Examples
37
38
 
38
39
  ```ruby
39
40
  # bad
40
- assert(collection.includes?(actual))
41
- assert(collection.includes?(actual), 'the message')
41
+ assert(collection.include?(object))
42
+ assert(collection.include?(object), 'the message')
42
43
 
43
44
  # good
44
- assert_includes(collection, actual)
45
- assert_includes(collection, actual, 'the message')
45
+ assert_includes(collection, object)
46
+ assert_includes(collection, object, 'the message')
46
47
  ```
47
48
 
48
49
  ### References
@@ -55,7 +56,8 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
55
56
  --- | --- | --- | --- | ---
56
57
  Enabled | Yes | Yes | 0.1 | -
57
58
 
58
- Check if your test uses `assert_nil` instead of `assert_equal(nil, something)`.
59
+ This cop enforces the test to use `assert_nil`
60
+ instead of using `assert_equal(nil, something)`.
59
61
 
60
62
  ### Examples
61
63
 
@@ -73,14 +75,39 @@ assert_nil(actual, 'the message')
73
75
 
74
76
  * [https://github.com/rubocop-hq/minitest-style-guide#assert-nil](https://github.com/rubocop-hq/minitest-style-guide#assert-nil)
75
77
 
78
+ ## Minitest/AssertRespondTo
79
+
80
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
81
+ --- | --- | --- | --- | ---
82
+ Enabled | Yes | Yes | 0.3 | -
83
+
84
+ This cop enforces the use of `assert_respond_to(object, :some_method)`
85
+ over `assert(object.respond_to?(:some_method))`.
86
+
87
+ ### Examples
88
+
89
+ ```ruby
90
+ # bad
91
+ assert(object.respond_to?(:some_method))
92
+ assert(object.respond_to?(:some_method), 'the message')
93
+
94
+ # good
95
+ assert_respond_to(object, :some_method)
96
+ assert_respond_to(object, :some_method, 'the message')
97
+ ```
98
+
99
+ ### References
100
+
101
+ * [https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method](https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method)
102
+
76
103
  ## Minitest/AssertTruthy
77
104
 
78
105
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
79
106
  --- | --- | --- | --- | ---
80
107
  Enabled | Yes | Yes | 0.2 | -
81
108
 
82
- Check if your test uses `assert(actual)`
83
- instead of `assert_equal(true, actual)`.
109
+ This cop enforces the test to use `assert(actual)`
110
+ instead of using `assert_equal(true, actual)`.
84
111
 
85
112
  ### Examples
86
113
 
@@ -98,13 +125,113 @@ assert(actual, 'the message')
98
125
 
99
126
  * [https://github.com/rubocop-hq/minitest-style-guide#assert-truthy](https://github.com/rubocop-hq/minitest-style-guide#assert-truthy)
100
127
 
128
+ ## Minitest/RefuteEmpty
129
+
130
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
131
+ --- | --- | --- | --- | ---
132
+ Enabled | Yes | Yes | 0.3 | -
133
+
134
+ This cop enforces to use `refute_empty` instead of
135
+ using `refute(object.empty?)`.
136
+
137
+ ### Examples
138
+
139
+ ```ruby
140
+ # bad
141
+ refute(object.empty?)
142
+ refute(object.empty?, 'the message')
143
+
144
+ # good
145
+ refute_empty(object)
146
+ refute_empty(object, 'the message')
147
+ ```
148
+
149
+ ### References
150
+
151
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-empty](https://github.com/rubocop-hq/minitest-style-guide#refute-empty)
152
+
153
+ ## Minitest/RefuteEqual
154
+
155
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
156
+ --- | --- | --- | --- | ---
157
+ Enabled | Yes | Yes | 0.3 | -
158
+
159
+ This cop enforces the use of `refute_equal(expected, object)`
160
+ over `assert_equal(expected != actual)` or `assert(! expected -= actual)`.
161
+
162
+ ### Examples
163
+
164
+ ```ruby
165
+ # bad
166
+ assert("rubocop-minitest" != actual)
167
+ assert(! "rubocop-minitest" == actual)
168
+
169
+ # good
170
+ refute_equal("rubocop-minitest", actual)
171
+ ```
172
+
173
+ ### References
174
+
175
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-equal](https://github.com/rubocop-hq/minitest-style-guide#refute-equal)
176
+
177
+ ## Minitest/RefuteFalse
178
+
179
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
180
+ --- | --- | --- | --- | ---
181
+ Enabled | Yes | Yes | 0.3 | -
182
+
183
+ This cop enforces the use of `refute(object)`
184
+ over `assert_equal(false, object)`.
185
+
186
+ ### Examples
187
+
188
+ ```ruby
189
+ # bad
190
+ assert_equal(false, actual)
191
+ assert_equal(false, actual, 'the message')
192
+
193
+ # good
194
+ refute(actual)
195
+ refute(actual, 'the message')
196
+ ```
197
+
198
+ ### References
199
+
200
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-false](https://github.com/rubocop-hq/minitest-style-guide#refute-false)
201
+
202
+ ## Minitest/RefuteIncludes
203
+
204
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
205
+ --- | --- | --- | --- | ---
206
+ Enabled | Yes | Yes | 0.3 | -
207
+
208
+ This cop enforces the test to use `refute_includes`
209
+ instead of using `refute(collection.include?(object))`.
210
+
211
+ ### Examples
212
+
213
+ ```ruby
214
+ # bad
215
+ refute(collection.include?(object))
216
+ refute(collection.include?(object), 'the message')
217
+
218
+ # good
219
+ refute_includes(collection, object)
220
+ refute_includes(collection, object, 'the message')
221
+ ```
222
+
223
+ ### References
224
+
225
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-includes](https://github.com/rubocop-hq/minitest-style-guide#refute-includes)
226
+
101
227
  ## Minitest/RefuteNil
102
228
 
103
229
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
104
230
  --- | --- | --- | --- | ---
105
231
  Enabled | Yes | Yes | 0.2 | -
106
232
 
107
- Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.
233
+ This cop enforces the test to use `refute_nil`
234
+ instead of using `refute_equal(nil, something)`.
108
235
 
109
236
  ### Examples
110
237
 
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.2.1
4
+ version: 0.3.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-09-24 00:00:00.000000000 Z
13
+ date: 2019-10-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -49,6 +49,7 @@ extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
51
  - ".circleci/config.yml"
52
+ - ".github/FUNDING.yml"
52
53
  - ".github/ISSUE_TEMPLATE/bug_report.md"
53
54
  - ".github/ISSUE_TEMPLATE/feature_request.md"
54
55
  - ".github/PULL_REQUEST_TEMPLATE.md"
@@ -68,7 +69,12 @@ files:
68
69
  - lib/rubocop/cop/minitest/assert_empty.rb
69
70
  - lib/rubocop/cop/minitest/assert_includes.rb
70
71
  - lib/rubocop/cop/minitest/assert_nil.rb
72
+ - lib/rubocop/cop/minitest/assert_respond_to.rb
71
73
  - lib/rubocop/cop/minitest/assert_truthy.rb
74
+ - lib/rubocop/cop/minitest/refute_empty.rb
75
+ - lib/rubocop/cop/minitest/refute_equal.rb
76
+ - lib/rubocop/cop/minitest/refute_false.rb
77
+ - lib/rubocop/cop/minitest/refute_includes.rb
72
78
  - lib/rubocop/cop/minitest/refute_nil.rb
73
79
  - lib/rubocop/cop/minitest_cops.rb
74
80
  - lib/rubocop/minitest.rb
@@ -107,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
113
  - !ruby/object:Gem::Version
108
114
  version: '0'
109
115
  requirements: []
110
- rubygems_version: 3.0.6
116
+ rubygems_version: 3.0.3
111
117
  signing_key:
112
118
  specification_version: 4
113
119
  summary: Automatic Minitest code style checking tool.