Skip to content

Commit

Permalink
Cover symbol methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marocchino committed Aug 9, 2023
1 parent 3bd0936 commit c86a27d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Master (Unreleased)

- Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when method is only non-word character. ([@marocchino])
- Fix a false positive for `RSpec/ReceiveMessages` when return with splat. ([@marocchino])

## 2.23.1 (2023-08-07)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/receive_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def heredoc_or_splat?(node)
end

def requires_quotes?(value)
value.match?(/^:".*?"|=$/)
value.match?(/^:".*?"|=$|^\W+$/)
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/rspec/receive_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
RUBY
end

it 'registers an offense when multiple messeages stubbed on the ' \
'same object and symbol methods' do
expect_offense(<<~RUBY)
before do
allow(Service).to receive(:`).and_return(true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `receive_messages` instead of multiple stubs on lines [3].
allow(Service).to receive(:[]).and_return(true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `receive_messages` instead of multiple stubs on lines [2].
end
RUBY

expect_correction(<<~RUBY)
before do
allow(Service).to receive_messages('`': true, '[]': true)
end
RUBY
end

it 'registers an offense when multiple messeages stubbed on the ' \
'same object and return array' do
expect_offense(<<~RUBY)
Expand Down

0 comments on commit c86a27d

Please sign in to comment.