lib/rubocop/cop/minitest/refute_equal.rb in rubocop-minitest-0.5.0 vs lib/rubocop/cop/minitest/refute_equal.rb in rubocop-minitest-0.5.1

- old
+ new

@@ -13,10 +13,12 @@ # # # good # refute_equal("rubocop-minitest", actual) # class RefuteEqual < Cop + include ArgumentRangeHelper + MSG = 'Prefer using `refute_equal(%<preferred>s)` over ' \ '`assert(%<over>s)`.' def_node_matcher :assert_not_equal, <<~PATTERN (send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... ) @@ -30,22 +32,19 @@ add_offense(node, message: message) end def autocorrect(node) lambda do |corrector| - assert_not_equal(node) do |_, first_arg, second_arg, rest_args| - autocorrect_node(node, corrector, first_arg, second_arg, rest_args) + assert_not_equal(node) do |_, expected, actual| + corrector.replace(node.loc.selector, 'refute_equal') + + replacement = [expected, actual].map(&:source).join(', ') + corrector.replace(first_argument_range(node), replacement) end end end private - - def autocorrect_node(node, corrector, first_arg, second_arg, rest_args) - custom_message = rest_args.first - replacement = preferred_usage(first_arg, second_arg, custom_message) - corrector.replace(node.loc.expression, "refute_equal(#{replacement})") - end def preferred_usage(first_arg, second_arg, custom_message = nil) [first_arg, second_arg, custom_message] .compact.map(&:source).join(', ') end