lib/rubocop/cop/minitest/refute_nil.rb in rubocop-minitest-0.5.0 vs lib/rubocop/cop/minitest/refute_nil.rb in rubocop-minitest-0.5.1
- old
+ new
@@ -14,10 +14,12 @@
# # good
# refute_nil(actual)
# refute_nil(actual, 'the message')
#
class RefuteNil < Cop
+ include ArgumentRangeHelper
+
MSG = 'Prefer using `refute_nil(%<arguments>s)` over ' \
'`refute_equal(nil, %<arguments>s)`.'
def_node_matcher :refute_equal_with_nil, <<~PATTERN
(send nil? :refute_equal nil $_ $...)
@@ -33,12 +35,15 @@
end
end
def autocorrect(node)
lambda do |corrector|
- arguments = node.arguments.reject(&:nil_type?)
- replacement = arguments.map(&:source).join(', ')
- corrector.replace(node.loc.expression, "refute_nil(#{replacement})")
+ refute_equal_with_nil(node) do |actual|
+ corrector.replace(node.loc.selector, 'refute_nil')
+ corrector.replace(
+ first_and_second_arguments_range(node), actual.source
+ )
+ end
end
end
end
end
end