lib/rubocop/cop/minitest/test_method_name.rb in rubocop-minitest-0.11.1 vs lib/rubocop/cop/minitest/test_method_name.rb in rubocop-minitest-0.12.0
- old
+ new
@@ -25,26 +25,27 @@
# class FooTest < Minitest::Test
# def helper_method(argument)
# end
# end
#
- class TestMethodName < Cop
+ class TestMethodName < Base
include MinitestExplorationHelpers
include DefNode
+ extend AutoCorrector
MSG = 'Test method name should start with `test_` prefix.'
def on_class(class_node)
return unless test_class?(class_node)
class_elements(class_node).each do |node|
- add_offense(node, location: :name) if offense?(node)
- end
- end
+ next unless offense?(node)
- def autocorrect(node)
- lambda do |corrector|
- corrector.replace(node.loc.name, "test_#{node.method_name}")
+ test_method_name = node.loc.name
+
+ add_offense(test_method_name) do |corrector|
+ corrector.replace(test_method_name, "test_#{node.method_name}")
+ end
end
end
private