Skip to content

Commit

Permalink
Change the start label of a heredocument to be enclosed in single quotes
Browse files Browse the repository at this point in the history
This PR is change as follows

```ruby
expect_offense(<<-RUBY)
  # ...
end

expect_offense(<<-'RUBY')
  # ...
end
```
  • Loading branch information
ydah committed Jan 10, 2023
1 parent 32a43ed commit aa0a9e3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
44 changes: 22 additions & 22 deletions spec/rubocop/cop/rspec/context_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
end

it 'finds context without `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'the display name not present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end

it 'finds shared_context without `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
shared_context 'the display name not present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end
Expand All @@ -43,38 +43,38 @@
end

it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'whenever you do' do
^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end

context 'with metadata hash' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'whenever you do', legend: true do
^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end
end

context 'with symbol metadata' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'whenever you do', :legend do
^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end
end

context 'with mixed metadata' do
it 'finds context without separate `when` at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'whenever you do', :legend, myth: true do
^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.
^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/.
end
RUBY
end
Expand All @@ -84,9 +84,9 @@
let(:cop_config) { { 'Prefixes' => %w[if], 'AllowedPatterns' => [] } }

it 'finds context without allowed prefixes at the beginning' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'when display name is present' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^if\\b/.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^if\b/.
end
RUBY
end
Expand Down Expand Up @@ -115,16 +115,16 @@
let(:cop_config) { { 'Prefixes' => ['a$b\d'], 'AllowedPatterns' => [] } }

it 'matches the full prefix' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'a' do
^^^ Context description should match /^a\\$b\\\\d\\b/.
^^^ Context description should match /^a\$b\\d\b/.
end
RUBY
end

it 'matches special characters' do
expect_no_offenses(<<-RUBY)
context 'a$b\\d something' do
expect_no_offenses(<<-'RUBY')
context 'a$b\d something' do
end
RUBY
end
Expand Down Expand Up @@ -166,18 +166,18 @@

it 'finds context without `when` at the beginning and not included ' \
'`/patterns/`' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
context 'this is an incorrect context' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /patterns/, or /^when\\b/.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /patterns/, or /^when\b/.
end
RUBY
end

it 'finds shared_context without `when` at the beginning and ' \
'not included `/patterns/`' do
expect_offense(<<-RUBY)
expect_offense(<<-'RUBY')
shared_context 'this is an incorrect context' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /patterns/, or /^when\\b/.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /patterns/, or /^when\b/.
end
RUBY
end
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rspec/example_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
end

it 'flags \-separated multiline strings' do
expect_offense(<<-RUBY)
it 'should do something ' \\
expect_offense(<<-'RUBY')
it 'should do something ' \
^^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
'and correctly fix' do
end
Expand Down
32 changes: 16 additions & 16 deletions spec/rubocop/cop/rspec/excessive_docstring_spacing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@

it 'skips \-separated multiline strings whose trailing whitespace ' \
'makes sense' do
expect_no_offenses(<<-RUBY)
describe '#mymethod ' \\
expect_no_offenses(<<-'RUBY')
describe '#mymethod ' \
'(is cool)' do
end
RUBY
end

it 'flags \-separated multiline strings whose trailing whitespace ' \
'does not make sense' do
expect_offense(<<-RUBY)
describe '#mymethod ' \\
expect_offense(<<-'RUBY')
describe '#mymethod ' \
^^^^^^^^^^^^^^^ Excessive whitespace.
'(is cool)' do
end
Expand Down Expand Up @@ -287,17 +287,17 @@

it 'skips \-separated multiline strings whose trailing whitespace ' \
'makes sense' do
expect_no_offenses(<<-RUBY)
context 'when doing something ' \\
expect_no_offenses(<<-'RUBY')
context 'when doing something ' \
'like this' do
end
RUBY
end

it 'flags \-separated multiline strings whose trailing whitespace ' \
'does not make sense' do
expect_offense(<<-RUBY)
context 'when doing something ' \\
expect_offense(<<-'RUBY')
context 'when doing something ' \
^^^^^^^^^^^^^^^^^^^^^^^^^^ Excessive whitespace.
'like this' do
end
Expand Down Expand Up @@ -479,17 +479,17 @@

it 'skips \-separated multiline strings whose trailing whitespace ' \
'makes sense' do
expect_no_offenses(<<-RUBY)
it 'should do something ' \\
expect_no_offenses(<<-'RUBY')
it 'should do something ' \
'and correctly fix' do
end
RUBY
end

it 'flags \-separated multiline strings whose trailing whitespace ' \
'does not make sense' do
expect_offense(<<-RUBY)
it 'does something ' \\
expect_offense(<<-'RUBY')
it 'does something ' \
^^^^^^^^^^^^^^^^^^^^ Excessive whitespace.
'and correctly fix' do
end
Expand Down Expand Up @@ -556,8 +556,8 @@
end

it 'supports `skip` (with a block)' do
expect_offense(<<-RUBY)
skip ' this please ' \\
expect_offense(<<-'RUBY')
skip ' this please ' \
^^^^^^^^^^^^^^^^^^^^^ Excessive whitespace.
' and thank you !' do
end
Expand All @@ -570,8 +570,8 @@
end

it 'supports `skip` (without a block)' do
expect_offense(<<-RUBY)
skip ' this please ' \\
expect_offense(<<-'RUBY')
skip ' this please ' \
^^^^^^^^^^^^^^^^^^^^^ Excessive whitespace.
' and thank you !'
RUBY
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/rspec/return_from_stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ def stub_foo
end

it 'finds concatenated strings with no variables' do
expect_offense(<<-RUBY)
allow(Foo).to receive(:bar).and_return('You called ' \\
expect_offense(<<-'RUBY')
allow(Foo).to receive(:bar).and_return('You called ' \
^^^^^^^^^^ Use block for static values.
'me')
RUBY

expect_correction(<<-RUBY)
allow(Foo).to receive(:bar) { 'You called ' \\
expect_correction(<<-'RUBY')
allow(Foo).to receive(:bar) { 'You called ' \
'me' }
RUBY
end
Expand Down

0 comments on commit aa0a9e3

Please sign in to comment.