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 Aug 7, 2023
1 parent 31bd569 commit 73195ea
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 @@ -4,6 +4,7 @@

- Drop Ruby 2.6 support. ([@ydah])
- Add new `Capybara/RSpec/PredicateMatcher` cop. ([@ydah])
- Change to default `EnforcedStyle: have_no` for `Capybara/NegationMatcher` cop. ([@ydah])

## 2.18.0 (2023-04-21)

Expand Down
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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 @@ -109,37 +109,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 @@ -148,7 +148,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 73195ea

Please sign in to comment.