Closed MatzFan closed 4 months ago
Your test class name should end in Test
:
Thanks. Same result with
class FooTest < Minitest::Test
def test_bar
assert_raises(ArgumentError) { Foo.new.bar('an_arg') }
end
def not_a_test
assert_raises(ArgumentError) { Foo.new.bar('an_arg') }
end
end
And if my test classes are not correctly named shouldn't that trigger another cop? TestFoo seems to be the correct convention for Minitest class names and is the one I've always used.
After renaming to FooTest
, I see this reported:
Offenses:
test/foo_test.rb:12:7: C: [Correctable] Minitest/TestMethodName: Test method name should start with test_ prefix.
def not_a_test
^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense autocorrectable
And if my test classes are not correctly named shouldn't that trigger another cop? TestFoo seems to be the correct convention for Minitest class names and is the one I've always used.
It's may be better to create a separate issue for discussing this. The Rails convention is to have the class name end with Test
, which is probably what most people follow (including RuboCop itelf), and so this hasn't been noticed.
OK, so after a class rename the problem is solved in my project. Agree 'Test' suffix is better anyhow. Thanks for your help.
No offense is registered with the following setup:
foo.rb
test_foo.rb
.rubocop.yml
Expected behavior
I expect an offense for the second method in the test file.
Actual behavior
No offense is registered.
Steps to reproduce the problem
Run
rubocop
orrubocop --require rubocop-minitest
in the root directory with the above files.RuboCop version