lib/rubocop/cop/rspec/example_wording.rb in rubocop-rspec-1.41.0 vs lib/rubocop/cop/rspec/example_wording.rb in rubocop-rspec-1.42.0
- old
+ new
@@ -28,10 +28,12 @@
#
# # good
# it 'does things' do
# end
class ExampleWording < Cop
+ extend AutoCorrector
+
MSG_SHOULD = 'Do not use should when describing your tests.'
MSG_IT = "Do not repeat 'it' when describing your tests."
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
IT_PREFIX = /\Ait /i.freeze
@@ -51,19 +53,16 @@
add_wording_offense(description_node, MSG_IT)
end
end
end
- def autocorrect(node)
- lambda do |corrector|
- corrector.replace(docstring(node), replacement_text(node))
- end
- end
-
private
def add_wording_offense(node, message)
- add_offense(node, location: docstring(node), message: message)
+ docstring = docstring(node)
+ add_offense(docstring, message: message) do |corrector|
+ corrector.replace(docstring, replacement_text(node))
+ end
end
def docstring(node)
expr = node.loc.expression