Skip to content

Commit 92bf3dd

Browse files
committed
Change to default EnforcedStyle: have_no for Capybara/NegationMatcher cop
Fix: #57
1 parent f265f29 commit 92bf3dd

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fix a false negative for `RSpec/HaveSelector` when first argument is dstr node. ([@ydah])
77
- Add new `Capybara/RedundantWithinFind` cop. ([@ydah])
88
- Fix an invalid attributes parse when name with multiple `[]` for `Capybara/SpecificFinders` and `Capybara/SpecificActions` and `Capybara/SpecificMatcher`. ([@ydah])
9+
- Change to default `EnforcedStyle: have_no` for `Capybara/NegationMatcher` cop. ([@ydah])
910

1011
## 2.19.0 (2023-09-20)
1112

config/default.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Capybara/NegationMatcher:
3737
Description: Enforces use of `have_no_*` or `not_to` for negated expectations.
3838
Enabled: pending
3939
VersionAdded: '2.14'
40-
EnforcedStyle: not_to
40+
VersionChanged: "<<next>>"
41+
EnforcedStyle: have_no
4142
SupportedStyles:
4243
- have_no
4344
- not_to

docs/modules/ROOT/pages/cops_capybara.adoc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,37 +170,37 @@ expect(page).to match_style(display: 'block')
170170
| Yes
171171
| Yes
172172
| 2.14
173-
| -
173+
| <<next>>
174174
|===
175175

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

178178
=== Examples
179179

180-
==== EnforcedStyle: not_to (default)
180+
==== EnforcedStyle: have_no (default)
181181

182182
[source,ruby]
183183
----
184184
# bad
185-
expect(page).to have_no_selector
186-
expect(page).to have_no_css('a')
187-
188-
# good
189185
expect(page).not_to have_selector
190186
expect(page).not_to have_css('a')
187+
188+
# good
189+
expect(page).to have_no_selector
190+
expect(page).to have_no_css('a')
191191
----
192192

193-
==== EnforcedStyle: have_no
193+
==== EnforcedStyle: not_to
194194

195195
[source,ruby]
196196
----
197197
# bad
198-
expect(page).not_to have_selector
199-
expect(page).not_to have_css('a')
200-
201-
# good
202198
expect(page).to have_no_selector
203199
expect(page).to have_no_css('a')
200+
201+
# good
202+
expect(page).not_to have_selector
203+
expect(page).not_to have_css('a')
204204
----
205205

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

211211
| EnforcedStyle
212-
| `not_to`
212+
| `have_no`
213213
| `have_no`, `not_to`
214214
|===
215215

lib/rubocop/cop/capybara/negation_matcher.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ module Cop
55
module Capybara
66
# Enforces use of `have_no_*` or `not_to` for negated expectations.
77
#
8-
# @example EnforcedStyle: not_to (default)
9-
# # bad
10-
# expect(page).to have_no_selector
11-
# expect(page).to have_no_css('a')
12-
#
13-
# # good
14-
# expect(page).not_to have_selector
15-
# expect(page).not_to have_css('a')
16-
#
17-
# @example EnforcedStyle: have_no
8+
# @example EnforcedStyle: have_no (default)
189
# # bad
1910
# expect(page).not_to have_selector
2011
# expect(page).not_to have_css('a')
@@ -23,6 +14,15 @@ module Capybara
2314
# expect(page).to have_no_selector
2415
# expect(page).to have_no_css('a')
2516
#
17+
# @example EnforcedStyle: not_to
18+
# # bad
19+
# expect(page).to have_no_selector
20+
# expect(page).to have_no_css('a')
21+
#
22+
# # good
23+
# expect(page).not_to have_selector
24+
# expect(page).not_to have_css('a')
25+
#
2626
class NegationMatcher < ::RuboCop::Cop::Base
2727
extend AutoCorrector
2828
include ConfigurableEnforcedStyle

0 commit comments

Comments
 (0)