Skip to content

Commit aa734b0

Browse files
authored
Merge pull request #1935 from jdufresne/right-single-quotation-mark
Make Rspec/ExampleWording handle Unicode RIGHT SINGLE QUOTATION MARK
2 parents 77f026b + 59d9db0 commit aa734b0

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
- Add support for Unicode RIGHT SINGLE QUOTATION MARK in `RSpec/ExampleWording`. ([@jdufresne])
6+
57
## 3.0.2 (2024-07-02)
68

79
- Fix wrong autocorrect for `RSpec/ScatteredSetup` when hook contains heredoc. ([@earlopain])

lib/rubocop/cop/rspec/example_wording.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class ExampleWording < Base
5555
MSG_INSUFFICIENT_DESCRIPTION = 'Your example description is ' \
5656
'insufficient.'
5757

58-
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
59-
WILL_PREFIX = /\A(?:will|won't)\b/i.freeze
58+
SHOULD_PREFIX = /\Ashould(?:n't|n’t)?\b/i.freeze
59+
WILL_PREFIX = /\A(?:will|won't|won’t)\b/i.freeze
6060
IT_PREFIX = /\Ait /i.freeze
6161

6262
# @!method it_description(node)

lib/rubocop/rspec/wording.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module RuboCop
44
module RSpec
55
# RSpec example wording rewriter
66
class Wording
7-
SHOULDNT_PREFIX = /\Ashould(?:n't| not)\b/i.freeze
7+
SHOULDNT_PREFIX = /\Ashould(?:n't|n’t| not)\b/i.freeze
88
SHOULDNT_BE_PREFIX = /#{SHOULDNT_PREFIX} be\b/i.freeze
99
WILL_NOT_PREFIX = /\Awill not\b/i.freeze
10-
WONT_PREFIX = /\Awon't\b/i.freeze
10+
WONT_PREFIX = /\Awo(?:n't|n’t)\b/i.freeze
1111
ES_SUFFIX_PATTERN = /(?:o|s|x|ch|sh|z)\z/i.freeze
1212
IES_SUFFIX_PATTERN = /[^aeou]y\z/i.freeze
1313

spec/rubocop/cop/rspec/example_wording_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@
148148
RUBY
149149
end
150150

151+
it 'finds description with `won’t` at the beginning' do
152+
expect_offense(<<~RUBY)
153+
it "won’t do something" do
154+
^^^^^^^^^^^^^^^^^^ Do not use the future tense when describing your tests.
155+
end
156+
RUBY
157+
158+
expect_correction(<<~RUBY)
159+
it "does not do something" do
160+
end
161+
RUBY
162+
end
163+
151164
it "finds description with `WON'T` at the beginning" do
152165
expect_offense(<<~RUBY)
153166
it "WON'T do something" do
@@ -161,6 +174,19 @@
161174
RUBY
162175
end
163176

177+
it 'finds description with `WON’T` at the beginning' do
178+
expect_offense(<<~RUBY)
179+
it "WON’T do something" do
180+
^^^^^^^^^^^^^^^^^^ Do not use the future tense when describing your tests.
181+
end
182+
RUBY
183+
184+
expect_correction(<<~RUBY)
185+
it "DOES NOT do something" do
186+
end
187+
RUBY
188+
end
189+
164190
it 'flags a lone will' do
165191
expect_offense(<<~RUBY)
166192
it 'will' do
@@ -200,6 +226,19 @@
200226
RUBY
201227
end
202228

229+
it 'flags a lone won’t' do
230+
expect_offense(<<~RUBY)
231+
it "won’t" do
232+
^^^^^ Do not use the future tense when describing your tests.
233+
end
234+
RUBY
235+
236+
expect_correction(<<~RUBY)
237+
it "does not" do
238+
end
239+
RUBY
240+
end
241+
203242
it 'finds leading its' do
204243
expect_offense(<<~RUBY)
205244
it "it does something" do

spec/rubocop/rspec/wording_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@
2424
'should wish me luck' => 'wishes me luck',
2525
'should really only return one item' => 'really only returns one item',
2626
"shouldn't return something" => 'does not return something',
27+
'shouldn’t return something' => 'does not return something',
2728
'SHOULD RETAIN UPPERCASE' => 'RETAINS UPPERCASE',
2829
"shouldn't be true" => 'is not true',
30+
'shouldn’t be true' => 'is not true',
2931
"SHOULDN'T BE true" => 'IS NOT true',
32+
'SHOULDN’T BE true' => 'IS NOT true',
3033
"SHOULDN'T NOT RETAIN UPPERCASE" => 'DOES NOT NOT RETAIN UPPERCASE',
34+
'SHOULDN’T NOT RETAIN UPPERCASE' => 'DOES NOT NOT RETAIN UPPERCASE',
3135
'should WORRY' => 'WORRIES',
3236
'should WISH me luck' => 'WISHES me luck',
3337
'' => '',
3438
'should' => '',
3539
"shouldn't" => 'does not',
40+
'shouldn’t' => 'does not',
3641
'should not' => 'does not',
3742
'should fizz' => 'fizzes'
3843
}

0 commit comments

Comments
 (0)