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

feat: support some "predicate" assertions in RSpec/Rails/MinitestAssertions #1789

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Jan 25, 2024

This implements some support for assert_predicate and co, focused on transforming usage with predicate methods (e.g. valid?) into their be_ equivalents.

Predicates that are not symbols or that don't end with ? are ignored - a follow up PR can expand support for other uses of assert_predicate.

I think technically this makes the autofix unsafe because assert_predicate uses send whereas RSpec uses send_public so you could assert a private method which would break when fixed, but I feel like that would generally be considered bad practice anyway and an easy mistake so arguably this could be useful?

Relates to rubocop/rubocop-rspec_rails#7


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop is configured as Enabled: true in .rubocop.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • Set VersionChanged: "<<next>>" in config/default.yml.

@G-Rath G-Rath requested a review from a team as a code owner January 25, 2024 22:51
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I agree that even though we deliberately suggest a potentially unsafe correction, it's for the greater good.

You're on fire with those assertion PRs 🔥

@pirj pirj requested a review from a team January 25, 2024 23:06
@pirj pirj merged commit 33ec2e0 into rubocop:master Jan 26, 2024
24 checks passed
@G-Rath G-Rath deleted the support-predicate branch January 26, 2024 17:38
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.

3 participants