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

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

Overview

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

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.'

Constants inherited from 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 Cop

inherited, #relevant_file?

Instance Method Details

#on_block(node) ⇒ Object



40
41
42
43
44
45
# File 'lib/rubocop/cop/rspec/context_wording.rb', line 40

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