Scoping autotest on the fly

Recently, I refactored some code that broke stuff all over the place, and autotest started spitting and re-running far too many failing specs for me to make much sense of it. I wanted a bit more control over what was watched and run.

Google to the rescue – it turned up this post by David Chelimsky that describes how to limit autotest’s scope to certain directories.

$ autotest models
$ autotest spec/lib lib

Nice. But I was jumping around quite frequently, and in many cases, I wanted to limit the scope to single files. Remembering autotest/menu.rb, I whipped up a quick module that let you reset the scope without having to restart autotest.

$ autotest
...
^C
1. Quit
2. Continue
3. Restart
4. Re-scope
> 4
New scope? models
...

Sweet. In addition to recognizing some magic words – models, controllers, views, lib, all – it also accepts a space-separated list of directories and files. As a final nicety, it also automatically adds the matching spec for models, controllers and libs, since autotest needs to know about both tests and implementations:

# Will add "app/models/user.rb" and "spec/models/user_spec.rb"
New scope? app/models/user.rb

That’s all. The file is available here: scope_menu.rb

AUTHOR:
dave
PUBLISHED:
July 02, 2008
UPDATED:
July 02, 2008

PREVIOUS:Mouse, louse, douse

NEXT:Commit!