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 to detect returns in test cases #236

Closed
fatkodima opened this issue Jan 28, 2023 · 3 comments · Fixed by #251
Closed

New cop to detect returns in test cases #236

fatkodima opened this issue Jan 28, 2023 · 3 comments · Fixed by #251
Labels
enhancement New feature or request

Comments

@fatkodima
Copy link
Contributor

# bad
def test_check_constraints
  return if mysql?
  # do testing
end

# good
def test_check_constraints
  skip("MySQL does not support check constraints") if mysql?
  # do testing
end

Example: https://github.com/gregnavis/active_record_doctor/blob/fc736812db046e2c0bfdbb6cec0b837e01a35076/test/active_record_doctor/detectors/mismatched_foreign_key_type_test.rb#L6

When using skip, minitest will report a skipped tests summary at the end; --verbose and --show-skips will show skips (https://github.com/minitest/minitest/blob/0984e29995a5c0f4dcf3c185442bcb4f493ed5e3/lib/minitest.rb#L208-L214); minitest-reporters will show the skipped tests; skip requires a reason with the existing cop (SkipWithoutReason) and overall it is more clear the intention, than just simple return.

@koic
Copy link
Member

koic commented Jan 29, 2023

This seems good idea. Can you open to the Minitest Style Guide first?
https://github.com/rubocop/minitest-style-guide

@fatkodima
Copy link
Contributor Author

@tejasbubane Thank you for the PR into the style guide! Do you want to implement this check too?

@tejasbubane
Copy link
Contributor

@fatkodima Yes I'll work on the implementation within a day or two.

@koic koic added the enhancement New feature or request label Mar 28, 2023
@koic koic closed this as completed in #251 Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants