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

Add new cop Minitest/NoTestCases #218

Merged
merged 1 commit into from
Mar 17, 2023
Merged

Conversation

tejasbubane
Copy link
Contributor

Closes #216


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@fatkodima
Copy link
Contributor

Lgtm 👍

@koic
Copy link
Member

koic commented Jan 6, 2023

I tried this cop with the rails/rails repo and it seems to find a lot of false positives. Could you take a look?

@koic
Copy link
Member

koic commented Jan 10, 2023

Isn't this rule too strict? I'm concerned that there are more opportunities for false positives than for detected true offenses. TBH, I don't have a sense of user-friendliness.

@fatkodima
Copy link
Contributor

Rails test suite defines lots of temp test classes without any tests. Some examples:

https://github.com/rails/rails/blob/b8e09fc54ec369574ff34734514600428dbd8a2a/activerecord/test/cases/validations/uniqueness_validation_test.rb#L49-L60
https://github.com/rails/rails/blob/b8e09fc54ec369574ff34734514600428dbd8a2a/railties/test/test_unit/reporter_test.rb#L8-L10
https://github.com/rails/rails/blob/b8e09fc54ec369574ff34734514600428dbd8a2a/activesupport/test/cache/stores/redis_cache_store_test.rb#L119-L140
I am not sure how to fix them safely. Any ideas?

First example: it just incorrectly detects non test class. That should be fixed.
Second example: Some empty test class to test the reporter. Regular projects do not extend test runners and do not have such classes.
Third example: This is a definition of a base test class - a popular practice and in this case the cop should be just disabled inline, in my opinion.

Personally, I see a value of this cop. Maybe not inside the rails itself, where "people know what they are doing"™️ and it would just generate false positives (I had not tested on it, probably there would be many valid offenses). But for regular projects this will produce many valid offenses. We can make it disabled by default, for example.

@koic
Copy link
Member

koic commented Mar 6, 2023

We can make it disabled by default, for example.

Yeah, it looks a reasonable idea. @tejasbubane Can you disable this cop by default?

@tejasbubane
Copy link
Contributor Author

@koic Disabled by default.

@koic koic merged commit 90cc740 into rubocop:master Mar 17, 2023
@tejasbubane tejasbubane deleted the fix-216 branch March 17, 2023 17:55
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 this pull request may close these issues.

New cop: Minitest/NoTestCases
3 participants