lib/rubocop/cop/rspec/context_wording.rb in rubocop-rspec-1.33.0 vs lib/rubocop/cop/rspec/context_wording.rb in rubocop-rspec-1.34.0

- old
+ new

@@ -1,23 +1,27 @@ # frozen_string_literal: true module RuboCop module Cop module RSpec - # `context` block descriptions should start with 'when', or 'with'. + # Checks that `context` docstring starts with an allowed prefix. # # @see https://github.com/reachlocal/rspec-style-guide#context-descriptions # @see http://www.betterspecs.org/#contexts # - # @example `Prefixes` configuration option, defaults: 'when', 'with', and - # 'without' - # Prefixes: - # - when - # - with - # - without - # - if + # @example `Prefixes` configuration # + # # .rubocop.yml + # # RSpec/ContextWording: + # # Prefixes: + # # - when + # # - with + # # - without + # # - if + # # - unless + # # - for + # # @example # # bad # context 'the display name not present' do # # ... # end @@ -33,33 +37,30 @@ (block (send #{RSPEC} { :context :shared_context } $(str #bad_prefix?) ...) ...) PATTERN def on_block(node) context_wording(node) do |context| - add_offense(context, message: message) + add_offense(context, + message: format(MSG, prefixes: joined_prefixes)) end end private def bad_prefix?(description) !prefixes.include?(description.split.first) end - def prefixes - cop_config['Prefixes'] || [] - end - - def message - format(MSG, prefixes: joined_prefixes) - end - def joined_prefixes quoted = prefixes.map { |prefix| "'#{prefix}'" } return quoted.first if quoted.size == 1 quoted << "or #{quoted.pop}" quoted.join(', ') + end + + def prefixes + cop_config['Prefixes'] || [] end end end end end