Skip to content

Commit

Permalink
Merge pull request #76 from rubocop/change_click_link_or_button_default
Browse files Browse the repository at this point in the history
Change to default `EnforcedStyle: link_or_button` for `Capybara/ClickLinkOrButtonStyle` cop
ydah authored Oct 11, 2023
2 parents c449767 + f94468d commit 355d09b
Showing 4 changed files with 43 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

## Edge (Unreleased)

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

## 2.19.0 (2023-09-20)

- Add new `Capybara/RSpec/PredicateMatcher` cop. ([@ydah])
7 changes: 4 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
@@ -10,13 +10,14 @@ Capybara:
- "**/features/step_definitions/**/*"

Capybara/ClickLinkOrButtonStyle:
Description: Checks for click button or link style.
Description: Checks for methods of button or link clicks.
Enabled: pending
VersionAdded: '2.19'
EnforcedStyle: strict
VersionChanged: "<<next>>"
EnforcedStyle: link_or_button
SupportedStyles:
- strict
- link_or_button
- strict
Reference: https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/ClickLinkOrButtonStyle

Capybara/CurrentPathExpectation:
35 changes: 21 additions & 14 deletions docs/modules/ROOT/pages/cops_capybara.adoc
Original file line number Diff line number Diff line change
@@ -9,37 +9,44 @@
| Yes
| No
| 2.19
| -
| <<next>>
|===

Checks for click button or link style.
Checks for methods of button or link clicks.

By default, prefer to use `click_link_or_button` or `click_on`.
These methods offer a weaker coupling between the test and HTML,
allowing for a more faithful reflection of how the user behaves.

You can set `EnforcedStyle: strict` to prefer the use of
`click_link` and `click_button`, but this is a deprecated setting.

=== Examples

==== EnforcedStyle: strict (default)
==== EnforcedStyle: link_or_button (default)

[source,ruby]
----
# bad
click_link_or_button('foo')
click_on('foo')
# good
click_link('foo')
click_button('foo')
# good
click_link_or_button('foo')
click_on('foo')
----

==== EnforcedStyle: link_or_button
==== EnforcedStyle: strict

[source,ruby]
----
# bad
click_link('foo')
click_button('foo')
# good
click_link_or_button('foo')
click_on('foo')
# good
click_link('foo')
click_button('foo')
----

=== Configurable attributes
@@ -48,8 +55,8 @@ click_on('foo')
| Name | Default value | Configurable values

| EnforcedStyle
| `strict`
| `strict`, `link_or_button`
| `link_or_button`
| `link_or_button`, `strict`
|===

=== References
25 changes: 16 additions & 9 deletions lib/rubocop/cop/capybara/click_link_or_button_style.rb
Original file line number Diff line number Diff line change
@@ -3,18 +3,16 @@
module RuboCop
module Cop
module Capybara
# Checks for click button or link style.
# Checks for methods of button or link clicks.
#
# @example EnforcedStyle: strict (default)
# # bad
# click_link_or_button('foo')
# click_on('foo')
# By default, prefer to use `click_link_or_button` or `click_on`.
# These methods offer a weaker coupling between the test and HTML,
# allowing for a more faithful reflection of how the user behaves.
#
# # good
# click_link('foo')
# click_button('foo')
# You can set `EnforcedStyle: strict` to prefer the use of
# `click_link` and `click_button`, but this is a deprecated setting.
#
# @example EnforcedStyle: link_or_button
# @example EnforcedStyle: link_or_button (default)
# # bad
# click_link('foo')
# click_button('foo')
@@ -23,6 +21,15 @@ module Capybara
# click_link_or_button('foo')
# click_on('foo')
#
# @example EnforcedStyle: strict
# # bad
# click_link_or_button('foo')
# click_on('foo')
#
# # good
# click_link('foo')
# click_button('foo')
#
class ClickLinkOrButtonStyle < ::RuboCop::Cop::Base
include ConfigurableEnforcedStyle

0 comments on commit 355d09b

Please sign in to comment.