Class: RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
Overview
Checks that no expectations are set on Capybara’s ‘current_path`.
The www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[‘have_current_path` matcher] should be used on `page` to set expectations on Capybara’s current path, since it uses github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara’s waiting functionality] which ensures that preceding actions (like ‘click_link`) have completed.
This cop does not support autocorrection in some cases.
Constant Summary collapse
- MSG =
'Do not set an RSpec expectation on `current_path` in ' \ 'Capybara feature specs - instead, use the ' \ '`have_current_path` matcher on `page`'
- RESTRICT_ON_SEND =
i[expect].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#as_is_matcher(node) ⇒ Object
Supported matchers: eq(…) / match(/regexp/) / match(‘regexp’).
- #expectation_set_on_current_path(node) ⇒ Object
- #on_send(node) ⇒ Object
- #regexp_str_matcher(node) ⇒ Object
Class Method Details
.autocorrect_incompatible_with ⇒ Object
61 62 63 |
# File 'lib/rubocop/cop/rspec/capybara/current_path_expectation.rb', line 61 def self.autocorrect_incompatible_with [Style::TrailingCommaInArguments] end |
Instance Method Details
#as_is_matcher(node) ⇒ Object
Supported matchers: eq(…) / match(/regexp/) / match(‘regexp’)
48 49 50 51 52 |
# File 'lib/rubocop/cop/rspec/capybara/current_path_expectation.rb', line 48 def_node_matcher :as_is_matcher, " (send\n #expectation_set_on_current_path ${:to :to_not :not_to}\n ${(send nil? :eq ...) (send nil? :match (regexp ...))})\n" |
#expectation_set_on_current_path(node) ⇒ Object
42 43 44 |
# File 'lib/rubocop/cop/rspec/capybara/current_path_expectation.rb', line 42 def_node_matcher :expectation_set_on_current_path, " (send nil? :expect (send {(send nil? :page) nil?} :current_path))\n" |
#on_send(node) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rubocop/cop/rspec/capybara/current_path_expectation.rb', line 65 def on_send(node) expectation_set_on_current_path(node) do add_offense(node.loc.selector) do |corrector| next unless node.chained? autocorrect(corrector, node) end end end |
#regexp_str_matcher(node) ⇒ Object
55 56 57 58 59 |
# File 'lib/rubocop/cop/rspec/capybara/current_path_expectation.rb', line 55 def_node_matcher :regexp_str_matcher, " (send\n #expectation_set_on_current_path ${:to :to_not :not_to}\n $(send nil? :match (str $_)))\n" |