Class: RuboCop::Cop::RSpec::Capybara::FeatureMethods
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
Overview
Checks for consistent method usage in feature specs.
By default, the cop disables all Capybara-specific methods that have the same native RSpec method (e.g. are just aliases). Some teams however may prefer using some of the Capybara methods (like ‘feature`) to make it obvious that the test uses Capybara, while still disable the rest of the methods, like `given` (alias for `let`), `background` (alias for `before`), etc. You can configure which of the methods to be enabled by using the EnabledMethods configuration option.
Constant Summary collapse
- MSG =
'Use `%<replacement>s` instead of `%<method>s`.'
- MAP =
{ background: :before, scenario: :it, xscenario: :xit, given: :let, given!: :let!, feature: :describe }.freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#message(range) ⇒ Object
86 87 88 89 |
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 86 def (range) name = range.source.to_sym format(MSG, method: name, replacement: MAP[name]) end |
#on_block(node) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 74 def on_block(node) return unless inside_spec?(node) feature_method(node) do |send_node, match| next if enabled?(match) add_offense(send_node.loc.selector) do |corrector| corrector.replace(send_node.loc.selector, MAP[match].to_s) end end end |