Recent Projects

Time Bomb Test

Sometimes you come across something in the Rails changelog that suggests a config change before upgrading to the next version. Sometimes you only have time to put some code together quickly, but you know that you really should go back and refactor it soon. How and where can you remind yourself about this stuff?

I’m not sure where I originally came across this concept, but I think it’s worth sharing again anyway. I’ll even give it a name this time. Time Bomb Tests: easy cheesy reminders you can put into your test suite. They’ll sit there like little time bomb reminders – exploding only when you need them to.

# test/integration/time_bomb_test.rb

require 'test_helper'

class TimeBombTest < ActionController::IntegrationTest

  test "stuff to do with next rails upgrade" do
    flunk if Rails.version != '2.2.2'
    # rename application.rb to application_controller.rb
    # etc...
  end

  test "stuff I'm putting off today, but really should do eventually" do
    flunk if Time.now > Time.parse('5/1/2009')
    # optimize that thing marked HACK in the user model
    # etc...
  end
end

Update: Check out jeremymcanally‘s deprecate, which appears to have been partially inspired by this post. It allows you to deprecate (primarily) test code after a certain date, version, or other arbitrary condition is met.

4 Responses to “Time Bomb Test”

  1. Hey Trevor, great idea. I already did that previously, as I documented here:

    http://blog.teksol.info/2005/12/08/non-immediate-unit-tests

    The idea of naming them though is something that hadn’t occured to me before. Great name!

  2. Trevor says:

    Thanks, François. Actually, that might have been where I first saw the technique. Very good idea, but it does help to have a nice nickname, huh? :)

  3. Jan Wedekind says:

    Hm. I hope I’ll remember next time to use this … Oh wait.

Leave a Reply