Class: RuboCop::Cop::Capybara::ClickLinkOrButtonStyle

Inherits:
Base
  • Object
show all
Includes:
ConfigurableEnforcedStyle
Defined in:
lib/rubocop/cop/capybara/click_link_or_button_style.rb

Overview

Checks for methods of button or link clicks.

This cop is deprecated. We plan to remove this in the next major version update to 3.0.

The migration target is ‘Capybara/AmbiguousClick`. It is only migration target when `EnforcedStyle: strict`. If you are using this cop, please plan for migration. There is no migration target when `EnforcedStyle: link_or_button`.

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: link_or_button (default)

# bad
click_link('foo')
click_button('foo')

# good
click_link_or_button('foo')
click_on('foo')

EnforcedStyle: strict

# bad
click_link_or_button('foo')
click_on('foo')

# good
click_link('foo')
click_button('foo')

Constant Summary collapse

MSG_STRICT =
'Use `click_link` or `click_button` instead of `%<method>s`.'
'Use `click_link_or_button` or `click_on` instead of `%<method>s`.'
STRICT_METHODS =
%i[click_link click_button].freeze
%i[click_link_or_button click_on].freeze
RESTRICT_ON_SEND =
(STRICT_METHODS + CLICK_LINK_OR_BUTTON).freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object


52
53
54
55
56
# File 'lib/rubocop/cop/capybara/click_link_or_button_style.rb', line 52

def on_send(node)
  return unless offense?(node)

  add_offense(node, message: offense_message(node))
end