Class: RuboCop::Cop::RSpec::Capybara::SpecificMatcher
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RSpec::Capybara::SpecificMatcher
- Defined in:
- lib/rubocop/cop/rspec/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
42 43 44 |
# File 'lib/rubocop/cop/rspec/capybara/specific_matcher.rb', line 42 def_node_matcher :first_argument, <<-PATTERN (send nil? _ (str $_) ... ) PATTERN |
#on_send(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubocop/cop/rspec/capybara/specific_matcher.rb', line 46 def on_send(node) first_argument(node) do |arg| next unless (matcher = specific_matcher(arg)) next if CssSelector.multiple_selectors?(arg) next unless CapybaraHelp.specific_option?(node, arg, matcher) next unless CapybaraHelp.specific_pseudo_classes?(arg) add_offense(node, message: (node, matcher)) end end |