Why I don’t use let/let! in my RSpec

At work, we're deciding on our test-writing style: let/let! blocks like let(:arg) { 5 } vs. instance variables defined in a setup method like @arg = 5. I've found no advantage to let; but I have experienced disadvantages. I've found no disadvantages to instance variables. And so, đź‘Ť for instance variables. I've written many specs … Continue reading Why I don’t use let/let! in my RSpec

Goodbye “X for Y”: the cryptic Ruby error is becoming friendlier

Anyone who's used Ruby has seen this message: r.rb:1:in `name': wrong number of arguments (3 for 2) (ArgumentError) This particular error has been driving me nuts for years. It's just so unnecessarily difficult to interpret — especially if Ruby's not the only language you use. I never remember which number is which. Compare to Python: TypeError: … Continue reading Goodbye “X for Y”: the cryptic Ruby error is becoming friendlier

Self-validating Ruby objects with ActiveModel Validations

I'm importing lots of CSV restaurant inspection data with Ruby, and I need to make sure the cleaned up data matches the spec. For example, a violation must have a business_id and date. It can optionally have a code and description. My goal was to be able to write a class like this: ...and it would … Continue reading Self-validating Ruby objects with ActiveModel Validations