rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

Suggestion: Advocate for predicate matchers

Open shepmaster opened this issue 9 years ago • 5 comments

# Bad
expect(foo).to eq nil
# Good
expect(foo).to be_nil
# Bad
expect(foo.baz?).to eq true
expect(foo.bar?).to eq false
# Good
expect(foo).to be_baz
expect(foo).to_not be_bar
# Bad
expect(foo).to eq 0
# Good
expect(foo).to be_zero

shepmaster avatar Aug 10 '16 15:08 shepmaster

Ah, I see #83 touches some (or all) of this.

shepmaster avatar Aug 10 '16 15:08 shepmaster

I'm writing a cop for this issue. I'll create a pull-request for it tomorrow. :laughing:

pocke avatar Aug 12 '17 14:08 pocke

#442 fixed some of these issues, but I guess eq(nil)be_nil and eq(0)be_zero still need to be addressed?

bquorning avatar Sep 21 '17 18:09 bquorning

eq(nil) -> be_nil is good, so we should add it. But eq(0) and be_zero are not equal. Because zero? is defined only Number class.

pocke avatar Sep 24 '17 08:09 pocke

The first case is actually value comparison vs identity comparison: #244.

bquorning avatar Sep 24 '17 14:09 bquorning