Skip to content

Commit

Permalink
Merge pull request #1396 from ydah/fix/1395
Browse files Browse the repository at this point in the history
Fix a wrong AllowedPatterns example in `RSpec/ContextWording`
  • Loading branch information
Darhazer authored Sep 28, 2022
2 parents 9c5c65a + 59b6b23 commit 61e154c
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 61e154c

Please sign in to comment.