lib/rubocop/cop/rspec/context_wording.rb in rubocop-rspec-2.18.1 vs lib/rubocop/cop/rspec/context_wording.rb in rubocop-rspec-2.19.0
- old
+ new
@@ -60,16 +60,16 @@
MSG = 'Context description should match %<patterns>s.'
# @!method context_wording(node)
def_node_matcher :context_wording, <<-PATTERN
- (block (send #rspec? { :context :shared_context } $(str $_) ...) ...)
+ (block (send #rspec? { :context :shared_context } $({str dstr xstr} ...) ...) ...)
PATTERN
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
- context_wording(node) do |context, description|
- if bad_pattern?(description)
+ context_wording(node) do |context|
+ if bad_pattern?(context)
message = format(MSG, patterns: expect_patterns)
add_offense(context, message: message)
end
end
end
@@ -82,13 +82,21 @@
def prefix_regexes
@prefix_regexes ||= prefixes.map { |pre| /^#{Regexp.escape(pre)}\b/ }
end
- def bad_pattern?(description)
+ def bad_pattern?(node)
return false if allowed_patterns.empty?
- !matches_allowed_pattern?(description)
+ !matches_allowed_pattern?(description(node))
+ end
+
+ def description(context)
+ if context.xstr_type?
+ context.value.value
+ else
+ context.value
+ end
end
def expect_patterns
inspected = allowed_patterns.map do |pattern|
pattern.inspect.gsub(/\A"|"\z/, '/')