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

[Tests only] Enable Minitest/AssertPredicate rule #49628

Merged

Conversation

nvasilevski
Copy link
Contributor

This commit enables Minitest/AssertPredicate rubocop rule and autocorrects violations

This is one of the rules which has very little to debate about. Using assert_predicate doesn't hurt readability but its greatest benefit in the error message it produces when the assertion fails. While regular assert will simply tell "expected false to be truthy" the assert_predicate produces a very helpful error message like "expected <your_object_inspect> to be :valid?" i.e. Expected <Order#asb123 id: 1> to be :shipped?

@@ -726,7 +726,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase

test "clearing change on reload" do
@user.highlights = [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ]
assert @user.highlights.attached?
assert_predicate @user.highlights, :attached?

@user.reload
assert_not @user.highlights.attached?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should extend the rubocop rule to also account for assert_not -> assert_not_predicate usages

@rafaelfranca rafaelfranca merged commit 1d11c76 into rails:main Oct 13, 2023
4 checks passed
@rafaelfranca rafaelfranca deleted the enable-minitest-assert-predicate-rubocop-rule branch October 13, 2023 19:51
koic added a commit to koic/rubocop-rails_config that referenced this pull request Oct 15, 2023
Follow up rails/rails#49628.

This PR enables `Minitest/AssertPredicate` cop.
koic added a commit to koic/rubocop-rails_config that referenced this pull request Oct 15, 2023
Follow up rails/rails#49628.

This PR enables `Minitest/AssertPredicate` cop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants