lib/rubocop/cop/rspec/implicit_expect.rb in rubocop-rspec-1.41.0 vs lib/rubocop/cop/rspec/implicit_expect.rb in rubocop-rspec-1.42.0
- old
+ new
@@ -23,10 +23,11 @@
#
# # good
# it { should be_truthy }
#
class ImplicitExpect < Cop
+ extend AutoCorrector
include ConfigurableEnforcedStyle
MSG = 'Prefer `%<good>s` over `%<bad>s`.'
def_node_matcher :implicit_expect, <<-PATTERN
@@ -52,23 +53,14 @@
if expectation_source.start_with?(style.to_s)
correct_style_detected
else
opposite_style_detected
- add_offense(
- node,
- location: source_range,
- message: offense_message(expectation_source)
- )
- end
- end
-
- def autocorrect(node)
- lambda do |corrector|
- offense = offending_expect(node)
- replacement = replacement_source(offense.source)
-
- corrector.replace(offense, replacement)
+ msg = offense_message(expectation_source)
+ add_offense(source_range, message: msg) do |corrector|
+ replacement = replacement_source(expectation_source)
+ corrector.replace(source_range, replacement)
+ end
end
end
private