class RuboCop::Cop::RSpec::ContextWording


end
# …
context ‘条件を満たすとき’ do
# good
end
# …
context ‘条件を満たす’ do
# bad
@example
# - /とき$/
# AllowedPatterns:
# RSpec/ContextWording:
# .rubocop.yml
@example ‘AllowedPatterns` configuration
with `AllowedPatterns`. By default, there are no checking by pattern.
This cop can be customized allowed context description pattern
end
# …
context ’when the display name is not present’ do
# good
end
# …
context ‘the display name not present’ do
# bad
@example
# - for
# - unless
# - if
# - without
# - with
# - when
# Prefixes:
# RSpec/ContextWording:
# .rubocop.yml
@example ‘Prefixes` configuration
@see www.betterspecs.org/#contexts<br>@see rspec.rubystyle.guide/#context-descriptions<br><br>They may consist of multiple words if desired.
include `if`, `unless`, `for`, `before`, `after`, or `during`.
the configuration to meet project needs. Other acceptable prefixes may
The default list of prefixes is minimal. Users are encouraged to tailor
Checks that `context` docstring starts with an allowed prefix.

def allowed_patterns

def allowed_patterns
  super + prefix_regexes
end

def bad_pattern?(description)

def bad_pattern?(description)
  return false if allowed_patterns.empty?
  !matches_allowed_pattern?(description)
end

def expect_patterns

def expect_patterns
  inspected = allowed_patterns.map(&:inspect)
  return inspected.first if inspected.size == 1
  inspected << "or #{inspected.pop}"
  inspected.join(', ')
end

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler

rubocop:disable InternalAffairs/NumblockHandler
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  context_wording(node) do |context, description|
    if bad_pattern?(description)
      message = format(MSG, patterns: expect_patterns)
      add_offense(context, message: message)
    end
  end
end

def prefix_regexes

def prefix_regexes
  @prefix_regexes ||= prefixes.map { |pre| /^#{Regexp.escape(pre)}\b/ }
end

def prefixes

def prefixes
  Array(cop_config.fetch('Prefixes', []))
end