From eb617486819a01ad76a08f50b0aa04cae3337dca Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Fri, 25 Oct 2024 17:24:09 +0300 Subject: [PATCH 1/2] Revert an change that would conceal unintentional RSpec syntax Specifically: expect { ... }.to change { ... }.by(...) and change { ... }.by(...) Here the usage of `and` is incorrect, as RSpec does not (and can't reasonably) support it. Compound should use the `and` method, not the operator, or the `&`. Same for `.or` and `|`. --- CHANGELOG.md | 1 + lib/rubocop/cop/rspec/change_by_zero.rb | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7dd725c9..f1de7a001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah]) - Fix an error for `RSpec/ChangeByZero` when `change (...) .by (0)` and `change (...)`, concatenated with `and` and `or`. ([@ydah]) +- Revert an change that would conceal unintentional RSpec syntax. ([@pirj]) ## 3.1.0 (2024-10-01) diff --git a/lib/rubocop/cop/rspec/change_by_zero.rb b/lib/rubocop/cop/rspec/change_by_zero.rb index 75d442c75..82da74193 100644 --- a/lib/rubocop/cop/rspec/change_by_zero.rb +++ b/lib/rubocop/cop/rspec/change_by_zero.rb @@ -118,11 +118,8 @@ def register_offense(node, change_node) # rubocop:enable Metrics/MethodLength def compound_expectations?(node) - if node.parent.send_type? + node.parent.send_type? && %i[and or & |].include?(node.parent.method_name) - else - node.parent.and_type? || node.parent.or_type? - end end def message(change_node) From 6cbe4238dd5a4881758b9504670fb6893bae1be8 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Fri, 25 Oct 2024 18:20:12 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1de7a001..14afa61bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ ## Master (Unreleased) - Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah]) -- Fix an error for `RSpec/ChangeByZero` when `change (...) .by (0)` and `change (...)`, concatenated with `and` and `or`. ([@ydah]) -- Revert an change that would conceal unintentional RSpec syntax. ([@pirj]) +- Add support for `and` and `or` compound matchers to `RSpec/ChangeByZero` cop. ([@ydah]) ## 3.1.0 (2024-10-01)