Class: RuboCop::Cop::RSpec::Capybara::SpecificMatcher
- Includes:
- RuboCop::Cop::RSpec::CapybaraHelp
- 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
Methods included from RuboCop::Cop::RSpec::CapybaraHelp
include_option?, replaceable_element?, replaceable_pseudo_class?, replaceable_pseudo_class_not?, replaceable_to_link?, specific_option?, specific_pseudo_classes?
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
#first_argument(node) ⇒ Object
44 45 46 |
# File 'lib/rubocop/cop/rspec/capybara/specific_matcher.rb', line 44 def_node_matcher :first_argument, <<-PATTERN (send nil? _ (str $_) ... ) PATTERN |
#on_send(node) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubocop/cop/rspec/capybara/specific_matcher.rb', line 48 def on_send(node) first_argument(node) do |arg| next unless (matcher = specific_matcher(arg)) next if CssSelector.multiple_selectors?(arg) next unless specific_option?(node, arg, matcher) next unless specific_pseudo_classes?(arg) add_offense(node, message: (node, matcher)) end end |