Class: RuboCop::Cop::RSpec::ContextMethod

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rspec/context_method.rb

Overview

`context` should not be used for specifying methods.

Examples:

# bad
context '#foo_bar' do
  # ...
end

context '.foo_bar' do
  # ...
end

# good
describe '#foo_bar' do
  # ...
end

describe '.foo_bar' do
  # ...
end

Constant Summary collapse

MSG =
'Use `describe` for testing methods.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_block(node) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/rubocop/cop/rspec/context_method.rb', line 35

def on_block(node)
  context_method(node) do |context|
    add_offense(context) do |corrector|
      corrector.replace(node.send_node.loc.selector, 'describe')
    end
  end
end