I thought I’d start a series of short blog posts on things I remark on during code review that could be of wider interest.
Do you see anything to improve in this extract from a feature spec, assuming we’re fine with doing assertions against the DB?
1 2 3 4 5
What happens if
item is nil? The test will explode on the last line with
NoMethodError: undefined method 'title' for nil:NilClass.
If we would instead do
then it would explode on that line, with
That’s a less cryptic error that triggers earlier, at the actual point where your assumption is wrong.
Active Record’s FinderMethods also include