Skip to content

Commit

Permalink
Merge pull request #60 from rubocop/fix/57
Browse files Browse the repository at this point in the history
Change to default `EnforcedStyle: have_no` for `Capybara/NegationMatcher` cop
  • Loading branch information
ydah authored Jan 2, 2024
2 parents f265f29 + 92bf3dd commit 4c0a43b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
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

0 comments on commit 4c0a43b

Please sign in to comment.