Skip to content

Commit

Permalink
Revert an change that would conceal unintentional RSpec syntax
Browse files Browse the repository at this point in the history
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 `|`.
  • Loading branch information
pirj committed Oct 25, 2024
1 parent 954a45f commit eb61748
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions lib/rubocop/cop/rspec/change_by_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eb61748

Please sign in to comment.