Skip to content

Conversation

@ydah
Copy link
Member

@ydah ydah commented Jun 18, 2023

Fix: #1660


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.

@ydah ydah mentioned this pull request Jul 17, 2023
@ydah ydah force-pushed the add-rspec-rails-negation-be-valid branch from 54c507a to afe023c Compare July 20, 2023 03:50
@ydah ydah force-pushed the add-rspec-rails-negation-be-valid branch from e4a9933 to b98d41f Compare July 20, 2023 03:53
@ydah ydah requested a review from bquorning July 20, 2023 03:53
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.

Nice, thank you!

@pirj pirj merged commit 9632317 into master Jul 20, 2023
@pirj pirj deleted the add-rspec-rails-negation-be-valid branch July 20, 2023 20:27
@r7kamura
Copy link
Contributor

r7kamura commented Aug 3, 2023

Is this cop safe?
Since it is not guaranteed that the test target is an instance of ActiveModel::Validations, I think it may cause false-positives from an object that responds to only #invalid? (or only #valid?).

@ojab
Copy link

ojab commented Aug 4, 2023

TBH quite a strange cop. As mentioned above, #[in]valid? is a pretty common method name for non-AR/AM objects, so it could braek something.
Also scope of the cop is just too small, AFAIU it's mostly about style of assertions where two methods exist and return opposite booleans, in that sense #valid? is no different from #odd?, i. e.

it { expect(1).to be_odd }
it { expect(1).not_to be_even }

Also using .not_to by default introducing inconsistencies, multiple expectations with .not_to, e. g.

expect(foo).not_to be_valid.and be_odd

are not supported and must be written as expect(foo).to be_invalid.and be_odd, so IMHO .to be_invalid is a more appropriate choice.

ydah added a commit that referenced this pull request Aug 6, 2023
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
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.

Cop idea: Negative be_valid matcher

6 participants