diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e80dd56..ff97feaf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/config/default.yml b/config/default.yml index 944922901..feeef2992 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveMessages RSpec/ReceiveNever: diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index f1c76d588..bcaa697db 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -4271,13 +4271,19 @@ expect(foo).to receive(:bar).at_most(:twice).times | Pending | Yes -| Yes +| Yes (Unsafe) | 2.23 -| - +| <> |=== 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] diff --git a/lib/rubocop/cop/rspec/receive_messages.rb b/lib/rubocop/cop/rspec/receive_messages.rb index 36a191ed0..2ab8606c0 100644 --- a/lib/rubocop/cop/rspec/receive_messages.rb +++ b/lib/rubocop/cop/rspec/receive_messages.rb @@ -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