rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
792 stars 272 forks source link

False negative for `RSpec/PredicateMatcher` when the expectations includes a custom assertion message #1929

Closed Earlopain closed 2 weeks ago

Earlopain commented 2 weeks ago

Config:

RSpec/PredicateMatcher:
  Strict: false

I have the following code:

expect(cop_names_without_department.include?(cop_name)).to be(false), "Missing department for #{cop_name}."

which I would expect to correct to:

expect(cop_names_without_department).not_to include(cop_name), "Missing department for #{cop_name}."

This happens because of the custom failure message at the end, offense happens correctly when its not present.

pirj commented 2 weeks ago

Nice catch, thanks for reporting.

The problem seems to be here, as this node matcher doesn’t expect the custom message. To teach it, this line may become:

$#boolean_matcher? …)

Would it fix the problem for you?

Earlopain commented 2 weeks ago

I can try that out in a bit. If that works, I'll make a pr with test for this. Thanks!

Edit: It works. Needs the same to apply for the different enforced style and then it's all good.