Scott W. Bradley

in which scottwb thinks out loud

Fork me on GitHub

Have Some Fun With Your Tests

| Comments

I just came across this test case in some old code I had forgotten about:

1
2
3
4
5
6
7
8
9
it "validates that the address is geocodable" do
  @user.address = "Death Star, Suite 1138"
  @user.city    = "Moon System"
  @user.state   = "Endor"
  @user.zipcode = "1138"

  expect{@user.save!}.to raise_exception ActiveRecord::RecordInvalid
  @user.errors[:address].should include "could not be found on the map"
end

It reminded me of something I actually think is important: have a little fun with the examples in your test cases. Not so much as to be distracting, but a little humor can add some fun to an otherwise mechanical, boring task.

I like to think of the guy who comes along a year later trying to understand my code by reading the tests. Telling a small story or making some pop-culture references will hopefully brighten his task.

Comments