Class: RuboCop::Cop::RSpec::ContextWording

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/context_wording.rb

Overview

Checks that `context` docstring starts with an allowed prefix.

The default list of prefixes is minimal. Users are encouraged to tailor the configuration to meet project needs. Other acceptable prefixes may include `if`, `unless`, `for`, `before`, `after`, or `during`.

Examples:

`Prefixes` configuration


# .rubocop.yml
# RSpec/ContextWording:
#   Prefixes:
#     - when
#     - with
#     - without
#     - if
#     - unless
#     - for
# bad
context 'the display name not present' do
  # ...
end

# good
context 'when the display name is not present' do
  # ...
end

See Also:

Constant Summary collapse

MSG =
'Start context description with %<prefixes>s.'

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


44
45
46
47
48
49
# File 'lib/rubocop/cop/rspec/context_wording.rb', line 44

def on_block(node)
  context_wording(node) do |context|
    add_offense(context,
                message: format(MSG, prefixes: joined_prefixes))
  end
end