Class: RuboCop::Cop::Capybara::SpecificFinders
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Capybara::SpecificFinders
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/capybara/specific_finders.rb
Overview
Checks if there is a more specific finder offered by Capybara.
Constant Summary collapse
- MSG =
'Prefer `find_by_id` over `find`.'- RESTRICT_ON_SEND =
i[find].freeze
Instance Method Summary collapse
Instance Method Details
#class_options(node) ⇒ Object
31 32 33 |
# File 'lib/rubocop/cop/capybara/specific_finders.rb', line 31 def_node_search :class_options, "(pair (sym :class) $_ ...)\n" |
#find_argument(node) ⇒ Object
26 27 28 |
# File 'lib/rubocop/cop/capybara/specific_finders.rb', line 26 def_node_matcher :find_argument, "(send _ :find $(sym {:css :id})? (str $_) ...)\n" |
#on_send(node) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/capybara/specific_finders.rb', line 35 def on_send(node) find_argument(node) do |sym, arg| next if CssSelector.pseudo_classes(arg).any? next if CssSelector.multiple_selectors?(arg) on_attr(node, sym, arg) if attribute?(arg) on_id(node, sym, arg) if CssSelector.id?(arg) on_sym_id(node, sym, arg) if sym.first&.value == :id end end |