Skip to content

Commit

Permalink
Merge pull request #1687 from rubocop/receive-messages-has-unsafe-aut…
Browse files Browse the repository at this point in the history
…ocorrection

Declare autocorrect as unsafe for `RSpec/ReceiveMessages`
  • Loading branch information
bquorning authored Aug 7, 2023
2 parents 4071f9b + 233faf2 commit 7e4e0d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

- Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop. ([@ydah])
- Declare autocorrect as unsafe for `RSpec/ReceiveMessages`. ([@bquorning])

## 2.23.0 (2023-07-30)

Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ RSpec/ReceiveCounts:
RSpec/ReceiveMessages:
Description: Checks for multiple messages stubbed on the same object.
Enabled: pending
SafeAutoCorrect: false
VersionAdded: '2.23'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveMessages

RSpec/ReceiveNever:
Expand Down
10 changes: 8 additions & 2 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4271,13 +4271,19 @@ expect(foo).to receive(:bar).at_most(:twice).times

| Pending
| Yes
| Yes
| Yes (Unsafe)
| 2.23
| -
| <<next>>
|===

Checks for multiple messages stubbed on the same object.

=== Safety

The autocorrection is marked as unsafe, because it may change the
order of stubs. This in turn may cause e.g. variables to be called
before they are defined.

=== Examples

[source,ruby]
Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/cop/rspec/receive_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module Cop
module RSpec
# Checks for multiple messages stubbed on the same object.
#
# @safety
# The autocorrection is marked as unsafe, because it may change the
# order of stubs. This in turn may cause e.g. variables to be called
# before they are defined.
#
# @example
# # bad
# before do
Expand Down

0 comments on commit 7e4e0d9

Please sign in to comment.