class RuboCop::Cop::Minitest::TestMethodName
end
end
def helper_method(argument)
class FooTest < Minitest::Test
# good
end
end
assert_equal 42, do_something
def test_does_something
class FooTest < Minitest::Test
# good
end
end
assert_equal 42, do_something
def does_something
class FooTest < Minitest::Test
# bad
@example
It aims to prevent tests that aren’t executed by forgetting to start test method name with ‘test_`.
Enforces that test method names start with `test_` prefix.
def offense?(node)
def offense?(node) return false if assertions(node).none? public?(node) && node.arguments.empty? && !test_method_name?(node) && !lifecycle_hook_method?(node) end
def on_class(class_node)
def on_class(class_node) return unless test_class?(class_node) class_def_nodes(class_node).each do |node| next unless offense?(node) 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
def public?(node)
def public?(node) !non_public?(node) end
def test_method_name?(node)
def test_method_name?(node) node.method_name.to_s.start_with?('test_') end