Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add cop for test class name #320

Open
MatzFan opened this issue Sep 10, 2024 · 0 comments
Open

[Enhancement] Add cop for test class name #320

MatzFan opened this issue Sep 10, 2024 · 0 comments

Comments

@MatzFan
Copy link

MatzFan commented Sep 10, 2024

Is your feature request related to a problem? Please describe.

Presently, Rubocop expects a test class name to end with "Test" and this is hard coded at this line. As per this comment using test class names like TestFoo (which happens to be the convention used by Minitest itself) results in Rubocop ignoring the methods in that test class entirely.

Describe the solution you'd like

I'd like to see:

  1. A new cop to detect where a test file includes a class which includes test methods but is not named according to the expected convention (i.e. class names not ending with "Test"). Note it would be important to ignore classes in test files with no test methods, so as to avoid false positives. It is easy (I've done it myself) to name a test class Foo (i.e. mistakenly omit the "Test" suffix) or to incorrectly name a test class with a typo - e.g. FooTst. In such cases all test methods included in the class are skipped by Rubocop, though the code will still run.
  2. Perhaps also the ability to configure the convention hard coded above such that a project could use the "TestFoo" convention instead. I'm not a Rails dev and was not aware of the Rails convention and I guess the demand for anything other than the "FooTest" convention may be vanishingly small, so this requirement may be unnecessary.

Describe alternatives you've considered

Leave as is and expect users to correctly name their test classes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant