Skip to content

Commit

Permalink
Change to default EnforcedStyle: have_no for `Capybara/NegationMatc…
Browse files Browse the repository at this point in the history
…her` cop

Fix: #57
  • Loading branch information
ydah committed Oct 2, 2023
1 parent c449767 commit cf61b83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Edge (Unreleased)

- Change to default `EnforcedStyle: have_no` for `Capybara/NegationMatcher` cop. ([@ydah])

## 2.19.0 (2023-09-20)

- Add new `Capybara/RSpec/PredicateMatcher` cop. ([@ydah])
Expand Down
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -163,37 +163,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 @@ -202,7 +202,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 cf61b83

Please sign in to comment.