Skip to content

Commit

Permalink
Add eql/equal support to RSpec/PredicateMatcher
Browse files Browse the repository at this point in the history
The `be_bool?` node matcher was already finding nodes using `eql` and
`equal`, but then didn't properly handle them.
  • Loading branch information
bquorning committed Feb 10, 2025
1 parent 285d92b commit 49b9b21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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)

- Don't let `RSpec/PredicateMatcher` replace `respond_to?` with two arguments with the RSpec `respond_to` matcher. ([@bquorning])
- Fix `RSpec/PredicateMatcher` support for `eql` and `equal` matchers. ([@bquorning])

## 3.4.0 (2025-01-20)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/predicate_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def rewrite_matcher(corrector, predicate, matcher)

def true?(to_symbol, matcher)
result = case matcher.method_name
when :be, :eq
when :be, :eq, :eql, :equal
matcher.first_argument.true_type?
when :be_truthy, :a_truthy_value
true
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rspec/predicate_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
expect(foo.empty?).to eq(true), 'fail'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
expect(foo.empty?).to eql(true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
expect(foo.empty?).to equal(true), 'whoops'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
expect(foo.empty?).not_to be(true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
expect(foo.empty?).to be(true)
Expand All @@ -226,6 +230,8 @@
expect_correction(<<~RUBY)
expect(foo).to be_empty
expect(foo).to be_empty, 'fail'
expect(foo).to be_empty
expect(foo).to be_empty, 'whoops'
expect(foo).not_to be_empty
expect(foo).to be_empty
expect(foo).not_to be_empty
Expand Down

0 comments on commit 49b9b21

Please sign in to comment.