Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare autocorrect as unsafe for RSpec/ReceiveMessages #1687

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
bquorning marked this conversation as resolved.
Show resolved Hide resolved
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