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 RSpec/Capybara/NegationMatcher cop #1405

Merged
merged 1 commit into from Oct 15, 2022
Merged

Conversation

ydah
Copy link
Member

@ydah ydah commented Oct 4, 2022

Resolve: #378


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 in default/config.yml to the next minor version.

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

  • [-] Set VersionChanged in config/default.yml to the next major version.

Copy link
Member

@Darhazer Darhazer left a comment

Choose a reason for hiding this comment

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

For spec completeness, can you add:
Case with heredoc for have_text (usually those are trickier for auto-correction, though we have some nice helpers to deal with those)

Test with argument, e.g. expect(page).not_to have_css('a') being corrected to expect(page).to have_no_css('a')

lib/rubocop/cop/rspec/capybara/negation_matcher.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/capybara/negation_matcher.rb Outdated Show resolved Hide resolved
@ydah ydah force-pushed the feature/378 branch 2 times, most recently from e797c6d to 88ab916 Compare October 5, 2022 11:40
@ydah ydah requested a review from Darhazer October 5, 2022 11:42
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.

Looks good.
Thank you for another useful contribution, @ydah!
Small suggestions below.

Would the cop tolerate compound expectations like:

expect(page)
  .to have_no_css('foo')
  .and have_no_css('bar')

And does it even make sense to insist on using not_to for compound expectations? (Similar to I believe #1349).

lib/rubocop/cop/rspec/capybara/negation_matcher.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/capybara/negation_matcher_spec.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/capybara/negation_matcher.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/capybara/negation_matcher.rb Outdated Show resolved Hide resolved
@pirj

This comment was marked as resolved.

@pirj pirj requested a review from bquorning October 10, 2022 15:54
@ydah

This comment was marked as resolved.

config/default.yml Outdated Show resolved Hide resolved
@ydah ydah force-pushed the feature/378 branch 3 times, most recently from bca5607 to 06d76fd Compare October 12, 2022 22:52
@bquorning bquorning removed their request for review October 13, 2022 19:52
@pirj pirj force-pushed the feature/378 branch 2 times, most recently from f871872 to e877c41 Compare October 13, 2022 20:52
@ydah ydah force-pushed the feature/378 branch 3 times, most recently from 2e3a942 to 3af2035 Compare October 14, 2022 01:34
@pirj pirj merged commit e95228d into rubocop:master Oct 15, 2022
@pirj
Copy link
Member

pirj commented Oct 15, 2022

Thank you, @ydah !

@ydah ydah deleted the feature/378 branch October 17, 2022 06:50
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: detect not_to have_selector capybara matchers
4 participants