class RuboCop::Cop::RSpec::Capybara::VisibilityMatcher

Checks for boolean visibility in capybara finders.

Capybara lets you find elements that match a certain visibility using the `:visible` option. `:visible` accepts both boolean and symbols as values, however using booleans can have unwanted effects. `visible: false` does not find just invisible elements, but both visible and invisible elements. For expressiveness and clarity, use one of the symbol values, `:all`, `:hidden` or `:visible`. (www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all)

@example

# bad
expect(page).to have_selector('.foo', visible: false)
expect(page).to have_css('.foo', visible: true)
expect(page).to have_link('my link', visible: false)

# good
expect(page).to have_selector('.foo', visible: :visible)
expect(page).to have_css('.foo', visible: :all)
expect(page).to have_link('my link', visible: :hidden)

Constants

CAPYBARA_MATCHER_METHODS
MSG_FALSE
MSG_TRUE
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/rspec/capybara/visibility_matcher.rb, line 59
def on_send(node)
  visible_false?(node) { |arg| add_offense(arg, message: MSG_FALSE) }
  visible_true?(node) { |arg| add_offense(arg, message: MSG_TRUE) }
end

Private Instance Methods

capybara_matcher?(method_name) click to toggle source
# File lib/rubocop/cop/rspec/capybara/visibility_matcher.rb, line 66
def capybara_matcher?(method_name)
  CAPYBARA_MATCHER_METHODS.include? method_name
end