-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from rubocop/to_ambiguous_click
Add `Capybara/AmbiguousClick` cop and make soft-deprecated `Capybara/ClickLinkOrButtonStyle` cop. If you want to use `EnforcedStyle: strict`, use `Capybara/AmbiguousClick` cop instead
- Loading branch information
Showing
8 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Capybara | ||
# Specify the exact target to click on. | ||
# | ||
# In projects where accessibility needs to be considered, | ||
# it is crucial to specify the click target precisely. | ||
# | ||
# @example | ||
# # bad | ||
# click_link_or_button('foo') | ||
# click_on('foo') | ||
# | ||
# # good | ||
# click_link('foo') | ||
# click_button('foo') | ||
# | ||
class AmbiguousClick < ::RuboCop::Cop::Base | ||
MSG = 'Use `click_link` or `click_button` instead of `%<method>s`.' | ||
RESTRICT_ON_SEND = %i[click_link_or_button click_on].freeze | ||
|
||
def on_send(node) | ||
add_offense(node, message: format(MSG, method: node.method_name)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Capybara::AmbiguousClick do | ||
it 'registers an offense when using `click_link_or_button`' do | ||
expect_offense(<<~RUBY) | ||
click_link_or_button('foo') | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `click_link` or `click_button` instead of `click_link_or_button`. | ||
RUBY | ||
end | ||
|
||
it 'registers an offense when using `click_on`' do | ||
expect_offense(<<~RUBY) | ||
click_on('foo') | ||
^^^^^^^^^^^^^^^ Use `click_link` or `click_button` instead of `click_on`. | ||
RUBY | ||
end | ||
|
||
it 'does not register an offense when using `click_link`' do | ||
expect_no_offenses(<<~RUBY) | ||
click_link('foo') | ||
RUBY | ||
end | ||
|
||
it 'does not register an offense when using `click_button`' do | ||
expect_no_offenses(<<~RUBY) | ||
click_button('foo') | ||
RUBY | ||
end | ||
end |