From 49b9b211a2c2c5fcb183961731ed4a9ac64a383e Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Sun, 9 Feb 2025 12:48:30 +0100 Subject: [PATCH] Add eql/equal support to RSpec/PredicateMatcher The `be_bool?` node matcher was already finding nodes using `eql` and `equal`, but then didn't properly handle them. --- CHANGELOG.md | 1 + lib/rubocop/cop/rspec/predicate_matcher.rb | 2 +- spec/rubocop/cop/rspec/predicate_matcher_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfa1cb0f..7a42c044d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rubocop/cop/rspec/predicate_matcher.rb b/lib/rubocop/cop/rspec/predicate_matcher.rb index e638889ed..b4b8ca412 100644 --- a/lib/rubocop/cop/rspec/predicate_matcher.rb +++ b/lib/rubocop/cop/rspec/predicate_matcher.rb @@ -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 diff --git a/spec/rubocop/cop/rspec/predicate_matcher_spec.rb b/spec/rubocop/cop/rspec/predicate_matcher_spec.rb index c2f5d2978..6f2429b1a 100644 --- a/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +++ b/spec/rubocop/cop/rspec/predicate_matcher_spec.rb @@ -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) @@ -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