rubocop-minitest 0.10.3 → 0.13.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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -3
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +5 -1
  4. data/.rubocop.yml +4 -1
  5. data/CHANGELOG.md +97 -52
  6. data/CONTRIBUTING.md +3 -3
  7. data/Gemfile +2 -2
  8. data/README.md +4 -4
  9. data/Rakefile +1 -1
  10. data/bin/console +2 -0
  11. data/config/default.yml +15 -4
  12. data/docs/antora.yml +1 -1
  13. data/docs/modules/ROOT/pages/cops.adoc +2 -0
  14. data/docs/modules/ROOT/pages/cops_minitest.adoc +71 -7
  15. data/docs/modules/ROOT/pages/index.adoc +1 -1
  16. data/legacy-docs/cops_minitest.md +16 -16
  17. data/legacy-docs/index.md +1 -1
  18. data/lib/rubocop/cop/minitest/assert_empty.rb +1 -1
  19. data/lib/rubocop/cop/minitest/assert_empty_literal.rb +12 -16
  20. data/lib/rubocop/cop/minitest/assert_equal.rb +1 -1
  21. data/lib/rubocop/cop/minitest/assert_in_delta.rb +4 -1
  22. data/lib/rubocop/cop/minitest/assert_includes.rb +1 -1
  23. data/lib/rubocop/cop/minitest/assert_instance_of.rb +1 -1
  24. data/lib/rubocop/cop/minitest/assert_kind_of.rb +1 -1
  25. data/lib/rubocop/cop/minitest/assert_match.rb +1 -1
  26. data/lib/rubocop/cop/minitest/assert_nil.rb +5 -11
  27. data/lib/rubocop/cop/minitest/assert_output.rb +1 -1
  28. data/lib/rubocop/cop/minitest/assert_path_exists.rb +6 -12
  29. data/lib/rubocop/cop/minitest/assert_respond_to.rb +1 -1
  30. data/lib/rubocop/cop/minitest/assert_silent.rb +8 -6
  31. data/lib/rubocop/cop/minitest/assert_truthy.rb +5 -11
  32. data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +41 -0
  33. data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +1 -1
  34. data/lib/rubocop/cop/minitest/global_expectations.rb +6 -7
  35. data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +15 -14
  36. data/lib/rubocop/cop/minitest/multiple_assertions.rb +2 -2
  37. data/lib/rubocop/cop/minitest/no_assertions.rb +48 -0
  38. data/lib/rubocop/cop/minitest/refute_empty.rb +1 -1
  39. data/lib/rubocop/cop/minitest/refute_equal.rb +6 -7
  40. data/lib/rubocop/cop/minitest/refute_false.rb +15 -22
  41. data/lib/rubocop/cop/minitest/refute_in_delta.rb +4 -1
  42. data/lib/rubocop/cop/minitest/refute_includes.rb +1 -1
  43. data/lib/rubocop/cop/minitest/refute_instance_of.rb +1 -1
  44. data/lib/rubocop/cop/minitest/refute_kind_of.rb +1 -1
  45. data/lib/rubocop/cop/minitest/refute_match.rb +1 -1
  46. data/lib/rubocop/cop/minitest/refute_nil.rb +4 -8
  47. data/lib/rubocop/cop/minitest/refute_path_exists.rb +6 -12
  48. data/lib/rubocop/cop/minitest/refute_respond_to.rb +1 -1
  49. data/lib/rubocop/cop/minitest/test_method_name.rb +9 -8
  50. data/lib/rubocop/cop/minitest/unspecified_exception.rb +1 -1
  51. data/lib/rubocop/cop/minitest_cops.rb +2 -0
  52. data/lib/rubocop/cop/mixin/in_delta_mixin.rb +5 -15
  53. data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +12 -12
  54. data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +14 -4
  55. data/lib/rubocop/minitest/version.rb +1 -1
  56. data/mkdocs.yml +1 -1
  57. data/relnotes/v0.1.0.md +1 -1
  58. data/relnotes/v0.10.0.md +12 -12
  59. data/relnotes/v0.10.1.md +1 -1
  60. data/relnotes/v0.10.2.md +1 -1
  61. data/relnotes/v0.10.3.md +1 -1
  62. data/relnotes/v0.11.0.md +16 -0
  63. data/relnotes/v0.11.1.md +5 -0
  64. data/relnotes/v0.12.0.md +10 -0
  65. data/relnotes/v0.12.1.md +5 -0
  66. data/relnotes/v0.13.0.md +5 -0
  67. data/relnotes/v0.2.0.md +4 -4
  68. data/relnotes/v0.2.1.md +1 -1
  69. data/relnotes/v0.3.0.md +6 -6
  70. data/relnotes/v0.4.0.md +5 -5
  71. data/relnotes/v0.4.1.md +1 -1
  72. data/relnotes/v0.5.0.md +1 -1
  73. data/relnotes/v0.5.1.md +1 -1
  74. data/relnotes/v0.6.0.md +1 -1
  75. data/relnotes/v0.6.1.md +2 -2
  76. data/relnotes/v0.6.2.md +1 -1
  77. data/relnotes/v0.7.0.md +5 -5
  78. data/relnotes/v0.8.0.md +4 -4
  79. data/relnotes/v0.8.1.md +1 -1
  80. data/relnotes/v0.9.0.md +3 -3
  81. data/rubocop-minitest.gemspec +5 -5
  82. data/tasks/cops_documentation.rake +10 -12
  83. metadata +17 -10
data/docs/antora.yml CHANGED
@@ -2,6 +2,6 @@ name: rubocop-minitest
2
2
  title: RuboCop Minitest
3
3
  # We always provide version without patch here (e.g. 1.1),
4
4
  # as patch versions should not appear in the docs.
5
- version: '0.10'
5
+ version: '0.13'
6
6
  nav:
7
7
  - modules/ROOT/nav.adoc
@@ -27,10 +27,12 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
27
27
  * xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo]
28
28
  * xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent]
29
29
  * xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
30
+ * xref:cops_minitest.adoc#minitestassertwithexpectedargument[Minitest/AssertWithExpectedArgument]
30
31
  * xref:cops_minitest.adoc#minitestassertioninlifecyclehook[Minitest/AssertionInLifecycleHook]
31
32
  * xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
32
33
  * xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
33
34
  * xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
35
+ * xref:cops_minitest.adoc#minitestnoassertions[Minitest/NoAssertions]
34
36
  * xref:cops_minitest.adoc#minitestrefuteempty[Minitest/RefuteEmpty]
35
37
  * xref:cops_minitest.adoc#minitestrefuteequal[Minitest/RefuteEqual]
36
38
  * xref:cops_minitest.adoc#minitestrefutefalse[Minitest/RefuteFalse]
@@ -41,19 +41,19 @@ assert_empty(object, 'message')
41
41
  | Yes
42
42
  | Yes (Unsafe)
43
43
  | 0.5
44
- | 0.10
44
+ | 0.11
45
45
  |===
46
46
 
47
47
  This cop enforces the test to use `assert_empty`
48
- instead of using `assert([], object)`.
48
+ instead of using `assert_equal([], object)`.
49
49
 
50
50
  === Examples
51
51
 
52
52
  [source,ruby]
53
53
  ----
54
54
  # bad
55
- assert([], object)
56
- assert({}, object)
55
+ assert_equal([], object)
56
+ assert_equal({}, object)
57
57
 
58
58
  # good
59
59
  assert_empty(object)
@@ -215,7 +215,7 @@ assert_kind_of(Class, object, 'message')
215
215
 
216
216
  === References
217
217
 
218
- * https://github.com/rubocop-hq/minitest-style-guide#assert-kind-of
218
+ * https://github.com/rubocop/minitest-style-guide#assert-kind-of
219
219
 
220
220
  == Minitest/AssertMatch
221
221
 
@@ -407,7 +407,7 @@ assert_silent { puts object.do_something }
407
407
 
408
408
  === References
409
409
 
410
- * https://github.com/rubocop-hq/minitest-style-guide#assert-silent
410
+ * https://github.com/rubocop/minitest-style-guide#assert-silent
411
411
 
412
412
  == Minitest/AssertTruthy
413
413
 
@@ -441,6 +441,38 @@ assert(actual, 'message')
441
441
 
442
442
  * https://minitest.rubystyle.guide#assert-truthy
443
443
 
444
+ == Minitest/AssertWithExpectedArgument
445
+
446
+ |===
447
+ | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
448
+
449
+ | Pending
450
+ | No
451
+ | No
452
+ | 0.11
453
+ | -
454
+ |===
455
+
456
+ This cop tries to detect when a user accidentally used
457
+ `assert` when they meant to use `assert_equal`.
458
+
459
+ It is marked as unsafe because it is not possible to determine
460
+ whether the second argument of `assert` is a message or not.
461
+
462
+ === Examples
463
+
464
+ [source,ruby]
465
+ ----
466
+ # bad
467
+ assert(3, my_list.length)
468
+ assert(expected, actual)
469
+
470
+ # good
471
+ assert_equal(3, my_list.length)
472
+ assert_equal(expected, actual)
473
+ assert(foo, 'message')
474
+ ----
475
+
444
476
  == Minitest/AssertionInLifecycleHook
445
477
 
446
478
  |===
@@ -593,6 +625,38 @@ end
593
625
  | Integer
594
626
  |===
595
627
 
628
+ == Minitest/NoAssertions
629
+
630
+ |===
631
+ | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
632
+
633
+ | Disabled
634
+ | Yes
635
+ | No
636
+ | 0.12
637
+ | -
638
+ |===
639
+
640
+ This cop checks if test cases contain any assertion calls.
641
+
642
+ === Examples
643
+
644
+ [source,ruby]
645
+ ----
646
+ # bad
647
+ class FooTest < Minitest::Test
648
+ def test_the_truth
649
+ end
650
+ end
651
+
652
+ # good
653
+ class FooTest < Minitest::Test
654
+ def test_the_truth
655
+ assert true
656
+ end
657
+ end
658
+ ----
659
+
596
660
  == Minitest/RefuteEmpty
597
661
 
598
662
  |===
@@ -817,7 +881,7 @@ refute_kind_of(Class, object, 'message')
817
881
 
818
882
  === References
819
883
 
820
- * https://github.com/rubocop-hq/minitest-style-guide#refute-kind-of
884
+ * https://github.com/rubocop/minitest-style-guide#refute-kind-of
821
885
 
822
886
  == Minitest/RefuteMatch
823
887
 
@@ -1,5 +1,5 @@
1
1
  = RuboCop Minitest
2
2
 
3
- A https://github.com/rubocop-hq/rubocop[RuboCop] extension focused on enforcing Minitest best practices and coding conventions.
3
+ A https://github.com/rubocop/rubocop[RuboCop] extension focused on enforcing Minitest best practices and coding conventions.
4
4
 
5
5
  It's based on the community-driven https://minitest.rubystyle.guide[Minitest style guide].
@@ -23,7 +23,7 @@ assert_empty(object, 'message')
23
23
 
24
24
  ### References
25
25
 
26
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-empty](https://github.com/rubocop-hq/minitest-style-guide#assert-empty)
26
+ * [https://github.com/rubocop/minitest-style-guide#assert-empty](https://github.com/rubocop/minitest-style-guide#assert-empty)
27
27
 
28
28
  ## Minitest/AssertEmptyLiteral
29
29
 
@@ -66,7 +66,7 @@ assert_equal("rubocop-minitest", actual)
66
66
 
67
67
  ### References
68
68
 
69
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-equal-arguments-order](https://github.com/rubocop-hq/minitest-style-guide#assert-equal-arguments-order)
69
+ * [https://github.com/rubocop/minitest-style-guide#assert-equal-arguments-order](https://github.com/rubocop/minitest-style-guide#assert-equal-arguments-order)
70
70
 
71
71
  ## Minitest/AssertIncludes
72
72
 
@@ -91,7 +91,7 @@ assert_includes(collection, object, 'message')
91
91
 
92
92
  ### References
93
93
 
94
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-includes](https://github.com/rubocop-hq/minitest-style-guide#assert-includes)
94
+ * [https://github.com/rubocop/minitest-style-guide#assert-includes](https://github.com/rubocop/minitest-style-guide#assert-includes)
95
95
 
96
96
  ## Minitest/AssertInstanceOf
97
97
 
@@ -116,7 +116,7 @@ assert_instance_of(Class, object, 'message')
116
116
 
117
117
  ### References
118
118
 
119
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of](https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of)
119
+ * [https://github.com/rubocop/minitest-style-guide#assert-instance-of](https://github.com/rubocop/minitest-style-guide#assert-instance-of)
120
120
 
121
121
  ## Minitest/AssertMatch
122
122
 
@@ -141,7 +141,7 @@ assert_match(matcher, string, 'message')
141
141
 
142
142
  ### References
143
143
 
144
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-match](https://github.com/rubocop-hq/minitest-style-guide#assert-match)
144
+ * [https://github.com/rubocop/minitest-style-guide#assert-match](https://github.com/rubocop/minitest-style-guide#assert-match)
145
145
 
146
146
  ## Minitest/AssertNil
147
147
 
@@ -166,7 +166,7 @@ assert_nil(actual, 'message')
166
166
 
167
167
  ### References
168
168
 
169
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-nil](https://github.com/rubocop-hq/minitest-style-guide#assert-nil)
169
+ * [https://github.com/rubocop/minitest-style-guide#assert-nil](https://github.com/rubocop/minitest-style-guide#assert-nil)
170
170
 
171
171
  ## Minitest/AssertRespondTo
172
172
 
@@ -193,7 +193,7 @@ assert_respond_to(self, :do_something)
193
193
 
194
194
  ### References
195
195
 
196
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method](https://github.com/rubocop-hq/minitest-style-guide#assert-responds-to-method)
196
+ * [https://github.com/rubocop/minitest-style-guide#assert-responds-to-method](https://github.com/rubocop/minitest-style-guide#assert-responds-to-method)
197
197
 
198
198
  ## Minitest/AssertTruthy
199
199
 
@@ -218,7 +218,7 @@ assert(actual, 'message')
218
218
 
219
219
  ### References
220
220
 
221
- * [https://github.com/rubocop-hq/minitest-style-guide#assert-truthy](https://github.com/rubocop-hq/minitest-style-guide#assert-truthy)
221
+ * [https://github.com/rubocop/minitest-style-guide#assert-truthy](https://github.com/rubocop/minitest-style-guide#assert-truthy)
222
222
 
223
223
  ## Minitest/GlobalExpectations
224
224
 
@@ -266,7 +266,7 @@ refute_empty(object, 'message')
266
266
 
267
267
  ### References
268
268
 
269
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-empty](https://github.com/rubocop-hq/minitest-style-guide#refute-empty)
269
+ * [https://github.com/rubocop/minitest-style-guide#refute-empty](https://github.com/rubocop/minitest-style-guide#refute-empty)
270
270
 
271
271
  ## Minitest/RefuteEqual
272
272
 
@@ -290,7 +290,7 @@ refute_equal("rubocop-minitest", actual)
290
290
 
291
291
  ### References
292
292
 
293
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-equal](https://github.com/rubocop-hq/minitest-style-guide#refute-equal)
293
+ * [https://github.com/rubocop/minitest-style-guide#refute-equal](https://github.com/rubocop/minitest-style-guide#refute-equal)
294
294
 
295
295
  ## Minitest/RefuteFalse
296
296
 
@@ -318,7 +318,7 @@ refute(actual, 'message')
318
318
 
319
319
  ### References
320
320
 
321
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-false](https://github.com/rubocop-hq/minitest-style-guide#refute-false)
321
+ * [https://github.com/rubocop/minitest-style-guide#refute-false](https://github.com/rubocop/minitest-style-guide#refute-false)
322
322
 
323
323
  ## Minitest/RefuteIncludes
324
324
 
@@ -343,7 +343,7 @@ refute_includes(collection, object, 'message')
343
343
 
344
344
  ### References
345
345
 
346
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-includes](https://github.com/rubocop-hq/minitest-style-guide#refute-includes)
346
+ * [https://github.com/rubocop/minitest-style-guide#refute-includes](https://github.com/rubocop/minitest-style-guide#refute-includes)
347
347
 
348
348
  ## Minitest/RefuteInstanceOf
349
349
 
@@ -368,7 +368,7 @@ refute_instance_of(Class, object, 'message')
368
368
 
369
369
  ### References
370
370
 
371
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of](https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of)
371
+ * [https://github.com/rubocop/minitest-style-guide#refute-instance-of](https://github.com/rubocop/minitest-style-guide#refute-instance-of)
372
372
 
373
373
  ## Minitest/RefuteMatch
374
374
 
@@ -393,7 +393,7 @@ refute_match(matcher, string, 'message')
393
393
 
394
394
  ### References
395
395
 
396
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-match](https://github.com/rubocop-hq/minitest-style-guide#refute-match)
396
+ * [https://github.com/rubocop/minitest-style-guide#refute-match](https://github.com/rubocop/minitest-style-guide#refute-match)
397
397
 
398
398
  ## Minitest/RefuteNil
399
399
 
@@ -418,7 +418,7 @@ refute_nil(actual, 'message')
418
418
 
419
419
  ### References
420
420
 
421
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-nil](https://github.com/rubocop-hq/minitest-style-guide#refute-nil)
421
+ * [https://github.com/rubocop/minitest-style-guide#refute-nil](https://github.com/rubocop/minitest-style-guide#refute-nil)
422
422
 
423
423
  ## Minitest/RefuteRespondTo
424
424
 
@@ -445,4 +445,4 @@ refute_respond_to(self, :do_something)
445
445
 
446
446
  ### References
447
447
 
448
- * [https://github.com/rubocop-hq/minitest-style-guide#refute-respond-to](https://github.com/rubocop-hq/minitest-style-guide#refute-respond-to)
448
+ * [https://github.com/rubocop/minitest-style-guide#refute-respond-to](https://github.com/rubocop/minitest-style-guide#refute-respond-to)
data/legacy-docs/index.md CHANGED
@@ -1 +1 @@
1
- A [RuboCop](https://github.com/rubocop-hq/rubocop) extension focused on enforcing Minitest best practices and coding conventions.
1
+ A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Minitest best practices and coding conventions.
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # assert_empty(object)
16
16
  # assert_empty(object, 'message')
17
17
  #
18
- class AssertEmpty < Cop
18
+ class AssertEmpty < Base
19
19
  extend MinitestCopRule
20
20
 
21
21
  define_rule :assert, target_method: :empty?
@@ -4,42 +4,38 @@ module RuboCop
4
4
  module Cop
5
5
  module Minitest
6
6
  # This cop enforces the test to use `assert_empty`
7
- # instead of using `assert([], object)`.
7
+ # instead of using `assert_equal([], object)`.
8
8
  #
9
9
  # @example
10
10
  # # bad
11
- # assert([], object)
12
- # assert({}, object)
11
+ # assert_equal([], object)
12
+ # assert_equal({}, object)
13
13
  #
14
14
  # # good
15
15
  # assert_empty(object)
16
16
  #
17
- class AssertEmptyLiteral < Cop
17
+ class AssertEmptyLiteral < Base
18
18
  include ArgumentRangeHelper
19
+ extend AutoCorrector
19
20
 
20
21
  MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
21
- '`assert(%<literal>s, %<arguments>s)`.'
22
+ '`assert_equal(%<literal>s, %<arguments>s)`.'
23
+ RESTRICT_ON_SEND = %i[assert_equal].freeze
22
24
 
23
- def_node_matcher :assert_with_empty_literal, <<~PATTERN
24
- (send nil? :assert ${hash array} $...)
25
+ def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN
26
+ (send nil? :assert_equal ${hash array} $...)
25
27
  PATTERN
26
28
 
27
29
  def on_send(node)
28
- assert_with_empty_literal(node) do |literal, matchers|
30
+ assert_equal_with_empty_literal(node) do |literal, matchers|
29
31
  return unless literal.values.empty?
30
32
 
31
33
  args = matchers.map(&:source).join(', ')
32
34
 
33
35
  message = format(MSG, literal: literal.source, arguments: args)
34
- add_offense(node, message: message)
35
- end
36
- end
37
-
38
- def autocorrect(node)
39
- assert_with_empty_literal(node) do |_literal, matchers|
40
- object = matchers.first
36
+ add_offense(node, message: message) do |corrector|
37
+ object = matchers.first
41
38
 
42
- lambda do |corrector|
43
39
  corrector.replace(node.loc.selector, 'assert_empty')
44
40
  corrector.replace(first_and_second_arguments_range(node), object.source)
45
41
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
  # # good
14
14
  # assert_equal("rubocop-minitest", actual)
15
15
  #
16
- class AssertEqual < Cop
16
+ class AssertEqual < Base
17
17
  extend MinitestCopRule
18
18
 
19
19
  define_rule :assert, target_method: :==, preferred_method: :assert_equal
@@ -15,8 +15,11 @@ module RuboCop
15
15
  # assert_in_delta(0.2, actual)
16
16
  # assert_in_delta(0.2, actual, 0.001, 'message')
17
17
  #
18
- class AssertInDelta < Cop
18
+ class AssertInDelta < Base
19
19
  include InDeltaMixin
20
+ extend AutoCorrector
21
+
22
+ RESTRICT_ON_SEND = %i[assert_equal].freeze
20
23
 
21
24
  def_node_matcher :equal_floats_call, <<~PATTERN
22
25
  (send nil? :assert_equal $_ $_ $...)
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # assert_includes(collection, object)
16
16
  # assert_includes(collection, object, 'message')
17
17
  #
18
- class AssertIncludes < Cop
18
+ class AssertIncludes < Base
19
19
  extend MinitestCopRule
20
20
 
21
21
  define_rule :assert, target_method: :include?, preferred_method: :assert_includes
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # assert_instance_of(Class, object)
16
16
  # assert_instance_of(Class, object, 'message')
17
17
  #
18
- class AssertInstanceOf < Cop
18
+ class AssertInstanceOf < Base
19
19
  extend MinitestCopRule
20
20
 
21
21
  define_rule :assert, target_method: :instance_of?, inverse: true
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # assert_kind_of(Class, object)
16
16
  # assert_kind_of(Class, object, 'message')
17
17
  #
18
- class AssertKindOf < Cop
18
+ class AssertKindOf < Base
19
19
  extend MinitestCopRule
20
20
 
21
21
  define_rule :assert, target_method: :kind_of?, inverse: true
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # assert_match(regex, string)
16
16
  # assert_match(matcher, string, 'message')
17
17
  #
18
- class AssertMatch < Cop
18
+ class AssertMatch < Base
19
19
  extend MinitestCopRule
20
20
 
21
21
  define_rule :assert, target_method: :match
@@ -15,11 +15,13 @@ module RuboCop
15
15
  # assert_nil(actual)
16
16
  # assert_nil(actual, 'message')
17
17
  #
18
- class AssertNil < Cop
18
+ class AssertNil < Base
19
19
  include ArgumentRangeHelper
20
+ extend AutoCorrector
20
21
 
21
22
  MSG = 'Prefer using `assert_nil(%<arguments>s)` over ' \
22
23
  '`assert_equal(nil, %<arguments>s)`.'
24
+ RESTRICT_ON_SEND = %i[assert_equal].freeze
23
25
 
24
26
  def_node_matcher :assert_equal_with_nil, <<~PATTERN
25
27
  (send nil? :assert_equal nil $_ $...)
@@ -31,17 +33,9 @@ module RuboCop
31
33
 
32
34
  arguments = [actual.source, message&.source].compact.join(', ')
33
35
 
34
- add_offense(node, message: format(MSG, arguments: arguments))
35
- end
36
- end
37
-
38
- def autocorrect(node)
39
- lambda do |corrector|
40
- assert_equal_with_nil(node) do |actual|
36
+ add_offense(node, message: format(MSG, arguments: arguments)) do |corrector|
41
37
  corrector.replace(node.loc.selector, 'assert_nil')
42
- corrector.replace(
43
- first_and_second_arguments_range(node), actual.source
44
- )
38
+ corrector.replace(first_and_second_arguments_range(node), actual.source)
45
39
  end
46
40
  end
47
41
  end