Class: RuboCop::Cop::RSpec::Capybara::FeatureMethods

Inherits:
RuboCop::Cop::RSpec::Cop show all
Defined in:
lib/rubocop/cop/rspec/capybara/feature_methods.rb

Overview

Checks for consistent method usage in feature specs.

Examples:

# bad
feature 'User logs in' do
  given(:user) { User.new }

  background do
    visit new_session_path
  end

  scenario 'with OAuth' do
    # ...
  end
end

# good
describe 'User logs in' do
  let(:user) { User.new }

  before do
    visit new_session_path
  end

  it 'with OAuth' do
    # ...
  end
end

Constant Summary collapse

MSG =
'Use `%<replacement>s` instead of `%<method>s`.'.freeze
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

Instance Method Summary collapse

Methods inherited from RuboCop::Cop::RSpec::Cop

inherited, #relevant_file?

Instance Method Details

#autocorrect(node) ⇒ Object



64
65
66
67
68
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 64

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.selector, MAP[node.method_name].to_s)
  end
end

#on_block(node) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rubocop/cop/rspec/capybara/feature_methods.rb', line 54

def on_block(node)
  feature_method(node) do |send_node, match|
    add_offense(
      send_node,
      location: :selector,
      message: format(MSG, method: match, replacement: MAP[match])
    )
  end
end