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

Change to default EnforcedStyle: have_no for Capybara/NegationMatcher cop #60

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fix a false negative for `RSpec/HaveSelector` when first argument is dstr node. ([@ydah])
- Add new `Capybara/RedundantWithinFind` cop. ([@ydah])
- Fix an invalid attributes parse when name with multiple `[]` for `Capybara/SpecificFinders` and `Capybara/SpecificActions` and `Capybara/SpecificMatcher`. ([@ydah])
- Change to default `EnforcedStyle: have_no` for `Capybara/NegationMatcher` cop. ([@ydah])

## 2.19.0 (2023-09-20)

Expand Down
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Capybara/NegationMatcher:
Description: Enforces use of `have_no_*` or `not_to` for negated expectations.
Enabled: pending
VersionAdded: '2.14'
EnforcedStyle: not_to
VersionChanged: "<<next>>"
EnforcedStyle: have_no
SupportedStyles:
- have_no
- not_to
Expand Down
24 changes: 12 additions & 12 deletions docs/modules/ROOT/pages/cops_capybara.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,37 +170,37 @@ expect(page).to match_style(display: 'block')
| Yes
| Yes
| 2.14
| -
| <<next>>
|===

Enforces use of `have_no_*` or `not_to` for negated expectations.

=== Examples

==== EnforcedStyle: not_to (default)
==== EnforcedStyle: have_no (default)

[source,ruby]
----
# bad
expect(page).to have_no_selector
expect(page).to have_no_css('a')

# good
expect(page).not_to have_selector
expect(page).not_to have_css('a')

# good
expect(page).to have_no_selector
expect(page).to have_no_css('a')
----

==== EnforcedStyle: have_no
==== EnforcedStyle: not_to

[source,ruby]
----
# bad
expect(page).not_to have_selector
expect(page).not_to have_css('a')

# good
expect(page).to have_no_selector
expect(page).to have_no_css('a')

# good
expect(page).not_to have_selector
expect(page).not_to have_css('a')
----

=== Configurable attributes
Expand All @@ -209,7 +209,7 @@ expect(page).to have_no_css('a')
| Name | Default value | Configurable values

| EnforcedStyle
| `not_to`
| `have_no`
| `have_no`, `not_to`
|===

Expand Down
20 changes: 10 additions & 10 deletions lib/rubocop/cop/capybara/negation_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ module Cop
module Capybara
# Enforces use of `have_no_*` or `not_to` for negated expectations.
#
# @example EnforcedStyle: not_to (default)
# # bad
# expect(page).to have_no_selector
# expect(page).to have_no_css('a')
#
# # good
# expect(page).not_to have_selector
# expect(page).not_to have_css('a')
#
# @example EnforcedStyle: have_no
# @example EnforcedStyle: have_no (default)
# # bad
# expect(page).not_to have_selector
# expect(page).not_to have_css('a')
Expand All @@ -23,6 +14,15 @@ module Capybara
# expect(page).to have_no_selector
# expect(page).to have_no_css('a')
#
# @example EnforcedStyle: not_to
# # bad
# expect(page).to have_no_selector
# expect(page).to have_no_css('a')
#
# # good
# expect(page).not_to have_selector
# expect(page).not_to have_css('a')
#
class NegationMatcher < ::RuboCop::Cop::Base
extend AutoCorrector
include ConfigurableEnforcedStyle
Expand Down