-
-
Couldn't load subscription status.
- Fork 283
Open
Labels
Description
RSpec/PredicateMatcher tells me to prefer the first form to the second one:
context 'given some result' do
let(:error) { 'Oops, a few things blew up and nothing worked' }
it 'check with nil?' do
expect(error.nil?).to be(true)
end
it 'check with be_nil' do
expect(error).to be_nil
end
endThis is gravely mistaken. It's longer, it's imo less clear, but much more importantly a failure (like in this example) gives uninformative info:
1) some example given some result check with nil?
Failure/Error: expect(error.nil?).to be(true)
expected true
got false
2) some example given some result check with be_nil
Failure/Error: expect(error).to be_nil
expected: nil
got: "Oops, a few things blew up and nothing worked"Notice how the second failure is much more informative, showing the unexpected error and all. That is the reason to always use precise matchers.
I don't mind if we keep the functionality for the (imo always bad) style, I don't care if we propose be_nil or eq(nil), but the default should change.
Let's minimize the reasons to curse at RuboCop.
pirj, schwern, jdufresne and mike-burns