Class: RuboCop::Cop::RSpec::Capybara::VisibilityMatcher
- Defined in:
- lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
Overview
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`. Read more in www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
Constant Summary collapse
- MSG_FALSE =
'Use `:all` or `:hidden` instead of `false`.'
- MSG_TRUE =
'Use `:visible` instead of `true`.'
- CAPYBARA_MATCHER_METHODS =
%i[ have_selector have_css have_xpath have_link have_button have_field have_select have_table have_checked_field have_unchecked_field have_text have_content ].freeze
- RESTRICT_ON_SEND =
CAPYBARA_MATCHER_METHODS
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#on_send(node) ⇒ Object
60 61 62 63 |
# File 'lib/rubocop/cop/rspec/capybara/visibility_matcher.rb', line 60 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 |
#visible_false?(node) ⇒ Object
56 57 58 |
# File 'lib/rubocop/cop/rspec/capybara/visibility_matcher.rb', line 56 def_node_matcher :visible_false?, <<~PATTERN (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) false) ...>)) PATTERN |
#visible_true?(node) ⇒ Object
51 52 53 |
# File 'lib/rubocop/cop/rspec/capybara/visibility_matcher.rb', line 51 def_node_matcher :visible_true?, <<~PATTERN (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) true) ...>)) PATTERN |