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.

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



44
45
46
47
48
# File 'lib/rubocop/cop/capybara/click_link_or_button_style.rb', line 44

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

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