Looking at micronaut made me realize that I often want to iterate very quickly on a single test, rather than having Autotest re-run every test in the file each time I save. After a quick chat with Ryan – whose suggestion was way simpler than what I was considering – here’s what popped out:

class Test::Unit::TestCase
  def self.focus *focused
    focused.collect! { |m| m.to_s }

      collect { |m| m.to_s }.
      select  { |m| m =~ /^test/ }.
      reject  { |m| focused.include? m }.
      each    { |m| undef_method m }

With this snippet in my test helper file, I can easily focus on just one test:

class MyTest < Test::Unit::TestCase
  # lots of tests

  def test_thingy
    # ...

  # lots more tests

  focus :test_thingy

…and remove the focus when I’m ready to zoom out. Awesome. Sprinkle on some editor support and it’ll be epic.

(2009-03-27: This is available in the latest ZenTest.)