rubocop-rspec
rubocop-rspec copied to clipboard
Suggestion: Advocate for predicate matchers
# 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
Ah, I see #83 touches some (or all) of this.
I'm writing a cop for this issue. I'll create a pull-request for it tomorrow. :laughing:
#442 fixed some of these issues, but I guess eq(nil) → be_nil and eq(0) → be_zero still need to be addressed?
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.
The first case is actually value comparison vs identity comparison: #244.