Skip to content

Commit

Permalink
Move the department associated with Capybara::RSpecMatchers to `Cap…
Browse files Browse the repository at this point in the history
…ybara/RSpec/*`
  • Loading branch information
ydah committed Jun 11, 2024
1 parent 4a923b2 commit 8a67f0e
Show file tree
Hide file tree
Showing 21 changed files with 672 additions and 636 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)

- Move the department associated with `Capybara::RSpecMatchers` to `Capybara/RSpec/*`. ([@ydah])

## 2.21.0 (2024-06-08)

- Fix a false negative for `Capybara/NegationMatcher` when using `to_not`. ([@ydah])
Expand Down
62 changes: 31 additions & 31 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,12 @@ Capybara/ClickLinkOrButtonStyle:
- strict
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/ClickLinkOrButtonStyle

Capybara/CurrentPathExpectation:
Description: Checks that no expectations are set on Capybara's `current_path`.
Enabled: true
VersionAdded: '1.18'
VersionChanged: '2.0'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/CurrentPathExpectation

Capybara/MatchStyle:
Description: Checks for usage of deprecated style methods.
Enabled: pending
VersionAdded: '2.17'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/MatchStyle

Capybara/NegationMatcher:
Description: Enforces use of `have_no_*` or `not_to` for negated expectations.
Enabled: pending
VersionAdded: '2.14'
VersionChanged: '2.20'
EnforcedStyle: have_no
SupportedStyles:
- have_no
- not_to
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/NegationMatcher

Capybara/RedundantWithinFind:
Description: Checks for redundant `within find(...)` calls.
Enabled: pending
Expand All @@ -62,30 +44,35 @@ Capybara/SpecificFinders:
VersionAdded: '2.13'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificFinders

Capybara/SpecificMatcher:
Description: Checks for there is a more specific matcher offered by Capybara.
Enabled: pending
VersionAdded: '2.12'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificMatcher

Capybara/VisibilityMatcher:
Description: Checks for boolean visibility in Capybara finders.
Enabled: true
VersionAdded: '1.39'
VersionChanged: '2.0'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/VisibilityMatcher

Capybara/RSpec:
Enabled: true
Include: *1

Capybara/RSpec/CurrentPathExpectation:
Description: Checks that no expectations are set on Capybara's `current_path`.
Enabled: true
VersionAdded: '1.18'
VersionChanged: '2.0'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/CurrentPathExpectation

Capybara/RSpec/HaveSelector:
Description: Use `have_css` or `have_xpath` instead of `have_selector`.
Enabled: pending
DefaultSelector: css
VersionAdded: '2.19'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/HaveSelector

Capybara/RSpec/NegationMatcher:
Description: Enforces use of `have_no_*` or `not_to` for negated expectations.
Enabled: pending
VersionAdded: '2.14'
VersionChanged: '2.20'
EnforcedStyle: have_no
SupportedStyles:
- have_no
- not_to
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/NegationMatcher

Capybara/RSpec/PredicateMatcher:
Description: Prefer using predicate matcher over using predicate method directly.
Enabled: pending
Expand All @@ -97,3 +84,16 @@ Capybara/RSpec/PredicateMatcher:
- explicit
VersionAdded: '2.19'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/PredicateMatcher

Capybara/RSpec/SpecificMatcher:
Description: Checks for there is a more specific matcher offered by Capybara.
Enabled: pending
VersionAdded: '2.12'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/SpecificMatcher

Capybara/RSpec/VisibilityMatcher:
Description: Checks for boolean visibility in Capybara finders.
Enabled: true
VersionAdded: '1.39'
VersionChanged: '2.0'
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/VisibilityMatcher
11 changes: 11 additions & 0 deletions config/obsoletion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Configuration of obsolete/deprecated cops used by `ConfigObsoletion`.
#
# See: https://docs.rubocop.org/rubocop/extensions.html#config-obsoletions
#

renamed:
Capybara/CurrentPathExpectation: Capybara/RSpec/CurrentPathExpectation
Capybara/NegationMatcher: Capybara/RSpec/NegationMatcher
Capybara/SpecificMatcher: Capybara/RSpec/SpecificMatcher
Capybara/VisibilityMatcher: Capybara/RSpec/VisibilityMatcher
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
=== Department xref:cops_capybara.adoc[Capybara]

* xref:cops_capybara.adoc#capybaraclicklinkorbuttonstyle[Capybara/ClickLinkOrButtonStyle]
* xref:cops_capybara.adoc#capybaracurrentpathexpectation[Capybara/CurrentPathExpectation]
* xref:cops_capybara.adoc#capybaramatchstyle[Capybara/MatchStyle]
* xref:cops_capybara.adoc#capybaranegationmatcher[Capybara/NegationMatcher]
* xref:cops_capybara.adoc#capybararedundantwithinfind[Capybara/RedundantWithinFind]
* xref:cops_capybara.adoc#capybaraspecificactions[Capybara/SpecificActions]
* xref:cops_capybara.adoc#capybaraspecificfinders[Capybara/SpecificFinders]
* xref:cops_capybara.adoc#capybaraspecificmatcher[Capybara/SpecificMatcher]
* xref:cops_capybara.adoc#capybaravisibilitymatcher[Capybara/VisibilityMatcher]

=== Department xref:cops_capybara_rspec.adoc[Capybara/RSpec]

* xref:cops_capybara_rspec.adoc#capybararspec/currentpathexpectation[Capybara/RSpec/CurrentPathExpectation]
* xref:cops_capybara_rspec.adoc#capybararspec/haveselector[Capybara/RSpec/HaveSelector]
* xref:cops_capybara_rspec.adoc#capybararspec/negationmatcher[Capybara/RSpec/NegationMatcher]
* xref:cops_capybara_rspec.adoc#capybararspec/predicatematcher[Capybara/RSpec/PredicateMatcher]
* xref:cops_capybara_rspec.adoc#capybararspec/specificmatcher[Capybara/RSpec/SpecificMatcher]
* xref:cops_capybara_rspec.adoc#capybararspec/visibilitymatcher[Capybara/RSpec/VisibilityMatcher]

// END_COP_LIST
182 changes: 0 additions & 182 deletions docs/modules/ROOT/pages/cops_capybara.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,6 @@ click_button('foo')
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/ClickLinkOrButtonStyle
== Capybara/CurrentPathExpectation
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Enabled
| Yes
| Always
| 1.18
| 2.0
|===
Checks that no expectations are set on Capybara's `current_path`.
The
https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
should be used on `page` to set expectations on Capybara's
current path, since it uses
https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
which ensures that preceding actions (like `click_link`) have
completed.
This cop does not support autocorrection in some cases.
=== Examples
[source,ruby]
----
# bad
expect(current_path).to eq('/callback')
expect(page.current_path).to eq('/callback')
# good
expect(page).to have_current_path('/callback', ignore_query: true)
# bad (does not support autocorrection when `match` with a variable)
expect(page).to match(variable)
----
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/CurrentPathExpectation
== Capybara/MatchStyle
|===
Expand Down Expand Up @@ -167,62 +124,6 @@ expect(page).to match_style(display: 'block')
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/MatchStyle
== Capybara/NegationMatcher
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| Always
| 2.14
| 2.20
|===
Enforces use of `have_no_*` or `not_to` for negated expectations.
=== Examples
==== EnforcedStyle: have_no (default)
[source,ruby]
----
# bad
expect(page).not_to have_selector 'a'
expect(page).not_to have_css('a')
# good
expect(page).to have_no_selector 'a'
expect(page).to have_no_css('a')
----
==== EnforcedStyle: not_to
[source,ruby]
----
# bad
expect(page).to have_no_selector 'a'
expect(page).to have_no_css('a')
# good
expect(page).not_to have_selector 'a'
expect(page).not_to have_css('a')
----
=== Configurable attributes
|===
| Name | Default value | Configurable values
| EnforcedStyle
| `have_no`
| `have_no`, `not_to`
|===
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/NegationMatcher
== Capybara/RedundantWithinFind
|===
Expand Down Expand Up @@ -332,86 +233,3 @@ find_by_id('some-id')
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificFinders
== Capybara/SpecificMatcher
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| No
| 2.12
| -
|===
Checks for there is a more specific matcher offered by Capybara.
=== Examples
[source,ruby]
----
# bad
expect(page).to have_selector('button')
expect(page).to have_no_selector('button.cls')
expect(page).to have_css('button')
expect(page).to have_no_css('a.cls', href: 'http://example.com')
expect(page).to have_css('table.cls')
expect(page).to have_css('select')
expect(page).to have_css('input', exact_text: 'foo')
# good
expect(page).to have_button
expect(page).to have_no_button(class: 'cls')
expect(page).to have_button
expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
expect(page).to have_table(class: 'cls')
expect(page).to have_select
expect(page).to have_field(with: 'foo')
----
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificMatcher
== Capybara/VisibilityMatcher
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Enabled
| Yes
| No
| 1.39
| 2.0
|===
Checks for boolean visibility in Capybara finders.
Capybara lets you find elements that match a certain visibility using
the `:visible` option. `:visible` accepts both boolean and symbols as
values, however using booleans can have unwanted effects. `visible:
false` does not find just invisible elements, but both visible and
invisible elements. For expressiveness and clarity, use one of the
symbol values, `:all`, `:hidden` or `:visible`.
Read more in
https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
=== Examples
[source,ruby]
----
# bad
expect(page).to have_selector('.foo', visible: false)
expect(page).to have_css('.foo', visible: true)
expect(page).to have_link('my link', visible: false)
# good
expect(page).to have_selector('.foo', visible: :visible)
expect(page).to have_css('.foo', visible: :all)
expect(page).to have_link('my link', visible: :hidden)
----
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/VisibilityMatcher
Loading

0 comments on commit 8a67f0e

Please sign in to comment.