Class: RuboCop::Cop::Mavenlint::UseFastCapybaraMatchers
- Inherits:
-
Cop
- Object
- Cop
- RuboCop::Cop::Mavenlint::UseFastCapybaraMatchers
- Defined in:
- lib/rubocop/cop/mavenlint/use_fast_capybara_matchers.rb
Overview
Identify usages of ‘to_not` with a Capybara matcher, which will be really slow.
For example
expect(page).to_not have_text('Hi')
Writing an assertion this way will first try to find the text ‘Hi’. If not present, Capybara will wait for the full timeout (often 30 seconds) before then inverting with ‘to_not` and passing.
Instead, we should do something like:
expect(page).to have_no_text('Hi')
Which will pass as soon as the text is not detected without any timeout.
Constant Summary collapse
- MSG =
'Use a `to have_no_*` selector. See https://github.com/mavenlink/welcome/wiki/Lint-Errors#usefastcapybaramatchers'.freeze
- CAPYBARA_MATCHERS =
%i(have_button have_checked_field have_content have_css have_field have_link have_select have_selector have_table have_text have_unchecked_field have_xpath)
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
32 33 34 35 36 |
# File 'lib/rubocop/cop/mavenlint/use_fast_capybara_matchers.rb', line 32 def on_send(node) return unless (node) add_offense(node) end |