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

Fix a false negative for RSpec/Capybara/VisibilityMatcher with negative matcher #1391

Merged
merged 2 commits into from
Sep 22, 2022

Conversation

ydah
Copy link
Member

@ydah ydah commented Sep 20, 2022

This PR fixes a problem with RSpec/Capybara/VisibilityMatcher
It is difficult to separate the PRs, and we have divided them into two commits in the PR and as a changelog, but please let us know if we need to separate the PRs.

@ commit 1 9778492

If :visible is specified for have_text and its alias method, have_content, it will result in an ArgumentError as follows.
Therefore, This PR is excluded have_text and have_content for RSpec/Capybara/VisibilityMatcher.

      Failure/Error: expect(page).to have_text('a', visible: true)

      ArgumentError:
        Invalid option(s) :visible, should be one of :count, :minimum, :maximum, :between, :wait, :exact, :normalize_ws
      # ./spec/capybara/sandbox_spec.rb:20:in `block (2 levels) in <top (required)>'

      Failure/Error: expect(page).to have_content('a', visible: true)

      ArgumentError:
        Invalid option(s) :visible, should be one of :count, :minimum, :maximum, :between, :wait, :exact, :normalize_ws
      # ./spec/capybara/sandbox_spec.rb:68:in `block (2 levels) in <top (required)>'

@ commit 2 b8883bc

Fix: #1390


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.

@ydah ydah marked this pull request as ready for review September 20, 2022 09:55
@ydah ydah changed the title Exclude methods that raise ArgumentError with RSpec/Capybara/VisibilityMatcher where :visible is an invalid option Fix a false negative for RSpec/Capybara/VisibilityMatcher with negative matcher. Sep 20, 2022
@ydah ydah changed the title Fix a false negative for RSpec/Capybara/VisibilityMatcher with negative matcher. Fix a false negative for RSpec/Capybara/VisibilityMatcher with negative matcher Sep 20, 2022
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.

Having those in one PR is fine 👍
Please fix the changelog (and take a look at the other comments, though they are not required changes)

CHANGELOG.md Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/capybara/visibility_matcher.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -3,6 +3,8 @@
## Master (Unreleased)

* Fix an error for `RSpec/Capybara/SpecificFinders` with no parentheses. ([@ydah][])
* Exclude methods that raise `ArgumentError` with `RSpec/Capybara/VisibilityMatcher` where `:visible` is an invalid option. ([@ydah][])
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it's better to list which elements were excluded.

Copy link
Member Author

Choose a reason for hiding this comment

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

That looks better. I have modified it to list it.

Copy link
Member

Choose a reason for hiding this comment

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

I think now you have to entries for the same commit

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, looks like the second commit contained an unnecessary entry. Fixed it.

have_unchecked_field
have_text
have_content
have_button have_checked_field have_css have_field have_link
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of such an approach:

%w[button
   checked_field
   css
   field 
   link
   select
   selector
   table
   unchecked_field
   xpath].flat_map { |element| ["have_#{element}", "have_no_#{element}"]}

That way we'd never forget to add the no_ version

Copy link
Member Author

@ydah ydah Sep 22, 2022

Choose a reason for hiding this comment

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

We had to make it a symbol, so I modified it a bit, how do you like it?

CHANGELOG.md Outdated Show resolved Hide resolved
…h `RSpec/Capybara/VisibilityMatcher` where `:visible` is an invalid option

If `:visible` is specified for `have_text` and its alias method,
`have_content`, it will result in an `ArgumentError` as follows.

Therefore, This PR is excluded `have_text` and `have_content`
for `RSpec/Capybara/VisibilityMatcher`.

```
      Failure/Error: expect(page).to have_text('a', visible: true)

      ArgumentError:
        Invalid option(s) :visible, should be one of :count, :minimum, :maximum, :between, :wait, :exact, :normalize_ws
      # ./spec/capybara/sandbox_spec.rb:20:in `block (2 levels) in <top (required)>'

      Failure/Error: expect(page).to have_content('a', visible: true)

      ArgumentError:
        Invalid option(s) :visible, should be one of :count, :minimum, :maximum, :between, :wait, :exact, :normalize_ws
      # ./spec/capybara/sandbox_spec.rb:68:in `block (2 levels) in <top (required)>'
```
@ydah ydah requested a review from Darhazer September 22, 2022 00:50
@bquorning bquorning mentioned this pull request Sep 22, 2022
6 tasks
@Darhazer Darhazer merged commit b6a1ec0 into rubocop:master Sep 22, 2022
@ydah ydah deleted the fix/visibilly_matcher branch September 22, 2022 19:41
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.

[RSpec/Capybara/VisibilityMatcher] False-negative for have_no_css
2 participants