Class: RuboCop::Cop::Capybara::SpecificMatcher
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Capybara::SpecificMatcher
- Defined in:
- lib/rubocop/cop/capybara/specific_matcher.rb
Overview
Checks for there is a more specific matcher offered by Capybara.
Constant Summary collapse
- MSG =
'Prefer `%<good_matcher>s` over `%<bad_matcher>s`.'
- RESTRICT_ON_SEND =
%i[have_selector have_no_selector have_css have_no_css].freeze
- SPECIFIC_MATCHER =
{ 'button' => 'button', 'a' => 'link', 'table' => 'table', 'select' => 'select', 'input' => 'field' }.freeze
Instance Method Summary collapse
Instance Method Details
#first_argument(node) ⇒ Object
41 42 43 |
# File 'lib/rubocop/cop/capybara/specific_matcher.rb', line 41 def_node_matcher :first_argument, <<~PATTERN (send nil? _ (str $_) ... ) PATTERN |
#on_send(node) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/capybara/specific_matcher.rb', line 50 def on_send(node) first_argument(node) do |arg| next unless (matcher = specific_matcher(arg)) next if CssSelector.multiple_selectors?(arg) next unless replaceable?(node, arg, matcher) add_offense(node, message: (node, matcher)) end end |
#text_with_regexp?(node) ⇒ Object
46 47 48 |
# File 'lib/rubocop/cop/capybara/specific_matcher.rb', line 46 def_node_search :text_with_regexp?, <<~PATTERN (pair (sym {:text :exact_text}) (regexp ...)) PATTERN |