Skip to content

Commit

Permalink
Require RuboCop 0.90 or higher due to use RESTRICT_ON_SEND
Browse files Browse the repository at this point in the history
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
  • Loading branch information
koic committed Mar 21, 2021
1 parent 7a08802 commit c792ccf
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
### Changes

* [#118](https://github.com/rubocop/rubocop-minitest/pull/118): **(BREAKING)** Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][])
* [#125](https://github.com/rubocop/rubocop-minitest/pull/125): Require RuboCop 0.90 or higher. ([@koic][])

## 0.10.3 (2021-01-12)

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/assert_empty_literal.rb
Expand Up @@ -19,6 +19,7 @@ class AssertEmptyLiteral < Cop

MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
'`assert_equal(%<literal>s, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[assert_equal].freeze

def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN
(send nil? :assert_equal ${hash array} $...)
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/minitest/assert_in_delta.rb
Expand Up @@ -18,6 +18,8 @@ module Minitest
class AssertInDelta < Cop
include InDeltaMixin

RESTRICT_ON_SEND = %i[assert_equal].freeze

def_node_matcher :equal_floats_call, <<~PATTERN
(send nil? :assert_equal $_ $_ $...)
PATTERN
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/assert_nil.rb
Expand Up @@ -20,6 +20,7 @@ class AssertNil < Cop

MSG = 'Prefer using `assert_nil(%<arguments>s)` over ' \
'`assert_equal(nil, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[assert_equal].freeze

def_node_matcher :assert_equal_with_nil, <<~PATTERN
(send nil? :assert_equal nil $_ $...)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/assert_path_exists.rb
Expand Up @@ -17,6 +17,7 @@ module Minitest
#
class AssertPathExists < Cop
MSG = 'Prefer using `%<good_method>s` over `%<bad_method>s`.'
RESTRICT_ON_SEND = %i[assert].freeze

def_node_matcher :assert_file_exists, <<~PATTERN
(send nil? :assert
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/assert_truthy.rb
Expand Up @@ -20,6 +20,7 @@ class AssertTruthy < Cop

MSG = 'Prefer using `assert(%<arguments>s)` over ' \
'`assert_equal(true, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[assert_equal].freeze

def_node_matcher :assert_equal_with_truthy, <<~PATTERN
(send nil? :assert_equal true $_ $...)
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/minitest/global_expectations.rb
Expand Up @@ -30,6 +30,8 @@ class GlobalExpectations < Cop

BLOCK_MATCHERS = %i[must_output must_raise must_be_silent must_throw].freeze

RESTRICT_ON_SEND = VALUE_MATCHERS + BLOCK_MATCHERS

VALUE_MATCHERS_STR = VALUE_MATCHERS.map do |m|
":#{m}"
end.join(' ').freeze
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/literal_as_actual_argument.rb
Expand Up @@ -21,6 +21,7 @@ class LiteralAsActualArgument < Cop
include ArgumentRangeHelper

MSG = 'Replace the literal with the first argument.'
RESTRICT_ON_SEND = %i[assert_equal].freeze

def on_send(node)
return unless node.method?(:assert_equal)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/refute_equal.rb
Expand Up @@ -19,6 +19,7 @@ class RefuteEqual < Cop

MSG = 'Prefer using `refute_equal(%<preferred>s)` over ' \
'`assert(%<over>s)`.'
RESTRICT_ON_SEND = %i[assert].freeze

def_node_matcher :assert_not_equal, <<~PATTERN
(send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... )
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/refute_false.rb
Expand Up @@ -25,6 +25,7 @@ class RefuteFalse < Cop
'`assert_equal(false, %<arguments>s)`.'
MSG_FOR_ASSERT = 'Prefer using `refute(%<arguments>s)` over ' \
'`assert(!%<arguments>s)`.'
RESTRICT_ON_SEND = %i[assert_equal assert].freeze

def_node_matcher :assert_equal_with_false, <<~PATTERN
(send nil? :assert_equal false $_ $...)
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/minitest/refute_in_delta.rb
Expand Up @@ -18,6 +18,8 @@ module Minitest
class RefuteInDelta < Cop
include InDeltaMixin

RESTRICT_ON_SEND = %i[refute_equal].freeze

def_node_matcher :equal_floats_call, <<~PATTERN
(send nil? :refute_equal $_ $_ $...)
PATTERN
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/refute_nil.rb
Expand Up @@ -20,6 +20,7 @@ class RefuteNil < Cop

MSG = 'Prefer using `refute_nil(%<arguments>s)` over ' \
'`refute_equal(nil, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[refute_equal].freeze

def_node_matcher :refute_equal_with_nil, <<~PATTERN
(send nil? :refute_equal nil $_ $...)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/minitest/refute_path_exists.rb
Expand Up @@ -17,6 +17,7 @@ module Minitest
#
class RefutePathExists < Cop
MSG = 'Prefer using `%<good_method>s` over `%<bad_method>s`.'
RESTRICT_ON_SEND = %i[refute].freeze

def_node_matcher :refute_file_exists, <<~PATTERN
(send nil? :refute
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/mixin/minitest_cop_rule.rb
Expand Up @@ -29,6 +29,7 @@ def define_rule(assertion_method, target_method:, preferred_method: nil, inverse
MSG = 'Prefer using `#{preferred_method}(%<new_arguments>s)` over ' \
'`#{assertion_method}(%<original_arguments>s)`.'
RESTRICT_ON_SEND = %i[#{assertion_method}].freeze
def on_send(node)
return unless node.method?(:#{assertion_method})
Expand Down

0 comments on commit c792ccf

Please sign in to comment.