Skip to content

Commit

Permalink
Fix a wrong AllowedPatterns example in RSpec/ContextWording
Browse files Browse the repository at this point in the history
Fix: #1395
  • Loading branch information
ydah committed Sep 26, 2022
1 parent d40542d commit 59b6b23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ end
# .rubocop.yml
# RSpec/ContextWording:
# AllowedPatterns:
# - /とき$/
# - とき$
----

[source,ruby]
Expand Down
6 changes: 4 additions & 2 deletions lib/rubocop/cop/rspec/context_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module RSpec
# # .rubocop.yml
# # RSpec/ContextWording:
# # AllowedPatterns:
# # - /とき$/
# # - とき$
#
# @example
# # bad
Expand Down Expand Up @@ -92,7 +92,9 @@ def bad_pattern?(description)
end

def expect_patterns
inspected = allowed_patterns.map(&:inspect)
inspected = allowed_patterns.map do |pattern|
pattern.inspect.gsub(/\A"|"\z/, '/')
end
return inspected.first if inspected.size == 1

inspected << "or #{inspected.pop}"
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/rspec/context_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
end
end

context 'when `AllowedPatterns: [/とき$/]`' do
context 'when `AllowedPatterns: [とき$]`' do
let(:cop_config) do
{ 'Prefixes' => [], 'AllowedPatterns' => [/とき$/] }
{ 'Prefixes' => [], 'AllowedPatterns' => ['とき$'] }
end

it 'finds context without `とき` at the ending' do
Expand All @@ -159,9 +159,9 @@
end
end

context 'when `Prefixes: [when]` and `AllowedPatterns: [/patterns/]`' do
context 'when `Prefixes: [when]` and `AllowedPatterns: [patterns]`' do
let(:cop_config) do
{ 'Prefixes' => %w[when], 'AllowedPatterns' => [/patterns/] }
{ 'Prefixes' => %w[when], 'AllowedPatterns' => ['patterns'] }
end

it 'finds context without `when` at the beginning and not included ' \
Expand Down

0 comments on commit 59b6b23

Please sign in to comment.