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

- old
+ new

@@ -16,10 +16,12 @@ # assert_respond_to(object, :some_method) # assert_respond_to(object, :some_method, 'the message') # assert_respond_to(self, some_method) # class AssertRespondTo < Cop + include ArgumentRangeHelper + MSG = 'Prefer using `assert_respond_to(%<preferred>s)` over ' \ '`assert(%<over>s)`.' def_node_matcher :assert_with_respond_to, <<~PATTERN (send nil? :assert $(send $_ :respond_to? $_) $...) @@ -35,14 +37,15 @@ end end def autocorrect(node) lambda do |corrector| - assert_with_respond_to(node) do |_, object, method, rest_args| - custom_message = rest_args.first - preferred = build_preferred_arguments(object, method, custom_message) - replacement = "assert_respond_to(#{preferred})" - corrector.replace(node.loc.expression, replacement) + assert_with_respond_to(node) do |_, object, method| + corrector.replace(node.loc.selector, 'assert_respond_to') + + object = object ? object.source : 'self' + replacement = [object, method.source].join(', ') + corrector.replace(first_argument_range(node), replacement) end end end private