Class: RuboCop::Cop::RSpec::Capybara::SpecificActions
- Defined in:
- lib/rubocop/cop/rspec/capybara/specific_actions.rb
Overview
Checks for there is a more specific actions offered by Capybara.
Constant Summary collapse
- MSG =
"Prefer `%<good_action>s` over `find('%<selector>s').click`."
- RESTRICT_ON_SEND =
%i[click].freeze
- SPECIFIC_ACTION =
{ 'button' => 'button', 'a' => 'link' }.freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
#block_pattern, #numblock_pattern, #send_pattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#click_on_selector(node) ⇒ Object
32 33 34 |
# File 'lib/rubocop/cop/rspec/capybara/specific_actions.rb', line 32 def_node_matcher :click_on_selector, <<-PATTERN (send _ :find (str $_) ...) PATTERN |
#on_send(node) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubocop/cop/rspec/capybara/specific_actions.rb', line 36 def on_send(node) click_on_selector(node.receiver) do |arg| next unless supported_selector?(arg) # Always check the last selector in the case of multiple selectors # separated by whitespace. # because the `.click` is executed on the element to # which the last selector points. next unless (selector = last_selector(arg)) next unless (action = specific_action(selector)) next unless CapybaraHelp.specific_option?(node.receiver, arg, action) next unless CapybaraHelp.specific_pseudo_classes?(arg) range = offense_range(node, node.receiver) add_offense(range, message: (action, selector)) end end |