Skip to content

[Enhancement] Add cop for test class name #320

@MatzFan

Description

@MatzFan

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions