lib/rubocop/cop/rspec/dialect.rb in rubocop-rspec-1.41.0 vs lib/rubocop/cop/rspec/dialect.rb in rubocop-rspec-1.42.0
- old
+ new
@@ -40,36 +40,29 @@
# # good
# describe 'display name presence' do
# # ...
# end
class Dialect < Cop
+ extend AutoCorrector
include MethodPreference
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
def_node_matcher :rspec_method?, ALL.send_pattern
def on_send(node)
return unless rspec_method?(node)
return unless preferred_methods[node.method_name]
- add_offense(node)
- end
+ msg = format(MSG, prefer: preferred_method(node.method_name),
+ current: node.method_name)
- def autocorrect(node)
- lambda do |corrector|
+ add_offense(node, message: msg) do |corrector|
current = node.loc.selector
preferred = preferred_method(current.source)
corrector.replace(current, preferred)
end
- end
-
- private
-
- def message(node)
- format(MSG, prefer: preferred_method(node.method_name),
- current: node.method_name)
end
end
end
end
end