lib/rubocop/cop/minitest/refute_equal.rb in rubocop-minitest-0.17.2 vs lib/rubocop/cop/minitest/refute_equal.rb in rubocop-minitest-0.18.0
- old
+ new
@@ -16,24 +16,23 @@
#
class RefuteEqual < Base
include ArgumentRangeHelper
extend AutoCorrector
- MSG = 'Prefer using `refute_equal(%<preferred>s)` over ' \
- '`assert(%<over>s)`.'
+ MSG = 'Prefer using `refute_equal(%<preferred>s)`.'
RESTRICT_ON_SEND = %i[assert].freeze
def_node_matcher :assert_not_equal, <<~PATTERN
- (send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... )
+ (send nil? :assert {(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... )
PATTERN
def on_send(node)
- preferred, over = process_not_equal(node)
- return unless preferred && over
+ preferred = process_not_equal(node)
+ return unless preferred
- assert_not_equal(node) do |_, expected, actual|
- message = format(MSG, preferred: preferred, over: over)
+ assert_not_equal(node) do |expected, actual|
+ message = format(MSG, preferred: preferred)
add_offense(node, message: message) do |corrector|
corrector.replace(node.loc.selector, 'refute_equal')
replacement = [expected, actual].map(&:source).join(', ')
@@ -52,14 +51,13 @@
def original_usage(first_part, custom_message)
[first_part, custom_message].compact.join(', ')
end
def process_not_equal(node)
- assert_not_equal(node) do |over, first_arg, second_arg, rest_args|
+ assert_not_equal(node) do |first_arg, second_arg, rest_args|
custom_message = rest_args.first
- preferred = preferred_usage(first_arg, second_arg, custom_message)
- over = original_usage(over.source, custom_message&.source)
- return [preferred, over]
+
+ preferred_usage(first_arg, second_arg, custom_message)
end
end
end
end
end