Time Bomb Test

by Trevor Turk

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.

http://media.mtvnservices.com/mgid:uma:video:mtv.com:9770

# test/integration/time_bomb_test.rb

require 'test_helper'

class TimeBombTest  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.

Advertisement