Class: RuboCop::Cop::Capybara::RSpec::HaveSelector

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/capybara/rspec/have_selector.rb

Overview

Use ‘have_css` or `have_xpath` instead of `have_selector`.

Examples:

# bad
expect(foo).to have_selector(:css, 'bar')

# good
expect(foo).to have_css('bar')

# bad
expect(foo).to have_selector(:xpath, 'bar')

# good
expect(foo).to have_xpath('bar')

DefaultSelector: css (default)

# bad
expect(foo).to have_selector('bar')

# good
expect(foo).to have_css('bar')

DefaultSelector: xpath

# bad
expect(foo).to have_selector('bar')

# good
expect(foo).to have_xpath('bar')

Constant Summary collapse

MSG =
'Use `%<good>s` instead of `have_selector`.'
RESTRICT_ON_SEND =
%i[have_selector].freeze
SELECTORS =
%i[css xpath].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



44
45
46
47
48
# File 'lib/rubocop/cop/capybara/rspec/have_selector.rb', line 44

def on_send(node)
  argument = node.first_argument
  on_select_with_type(node, argument) if argument.sym_type?
  on_select_without_type(node) if %i[str dstr].include?(argument.type)
end