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

New cop: Minitest/TestFileName #213

Closed
fatkodima opened this issue Dec 30, 2022 · 6 comments · Fixed by #217
Closed

New cop: Minitest/TestFileName #213

fatkodima opened this issue Dec 30, 2022 · 6 comments · Fixed by #217

Comments

@fatkodima
Copy link
Contributor

This cop should check if we have a test class inside the file without the _test suffix.
In this case, this file will be just ignored when running all the tests and go unnoticed.

@koic
Copy link
Member

koic commented Dec 30, 2022

Can you point out bad and good cases with code?

@fatkodima
Copy link
Contributor Author

Bad

# Defined in test/something.rb file
class SomethingTest < Minitest::Test
  def test_foo
    # ...
  end
end

Good

# Defined in test/something_test.rb file
class SomethingTest < Minitest::Test
  def test_foo
    # ...
  end
end

@tejasbubane
Copy link
Contributor

I guess this cop will be very similar to RSpec/FilePath.

@fatkodima
Copy link
Contributor Author

Yes. Rspec's cop enforces that the file is named as a tested class also (besides the suffix). In minitest, sometimes in a single test file there are multiple test classes (a rails/rails is a good example). So I would not enforce that, or maybe under some flag.

@andyw8
Copy link
Contributor

andyw8 commented Dec 30, 2022

I added a guideline relating to this to the styleguide a while ago:

https://github.com/rubocop/minitest-style-guide#file-naming

And I just opened this PR:
rubocop/minitest-style-guide#52

tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
@andyw8
Copy link
Contributor

andyw8 commented Dec 30, 2022

(Brief reply as I'm on mobile). The naming convention could be configurable, to avoid the risk of the file name not matching an expected pattern, e.g. *_test

tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Dec 30, 2022
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Jan 1, 2023
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Jan 1, 2023
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Jan 1, 2023
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Jan 1, 2023
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Jan 9, 2023
@koic koic closed this as completed in #217 Jan 10, 2023
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

Successfully merging a pull request may close this issue.

4 participants