Class: RuboCop::Cop::RSpec::Capybara::FeatureMethods
- Inherits:
-
RuboCop::Cop::RSpec::Cop
- Object
- WorkaroundCop
- RuboCop::Cop::RSpec::Cop
- RuboCop::Cop::RSpec::Capybara::FeatureMethods
- 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
Constants inherited from RuboCop::Cop::RSpec::Cop
RuboCop::Cop::RSpec::Cop::DEFAULT_CONFIGURATION, RuboCop::Cop::RSpec::Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from RuboCop::Cop::RSpec::Cop
Instance Method Details
#autocorrect(node) ⇒ Object
82 83 84 85 86 |
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 82 def autocorrect(node) lambda do |corrector| corrector.replace(node.loc.selector, MAP[node.method_name].to_s) end end |
#on_block(node) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 68 def on_block(node) return unless inside_spec?(node) feature_method(node) do |send_node, match| next if enabled?(match) add_offense( send_node, location: :selector, message: format(MSG, method: match, replacement: MAP[match]) ) end end |