Autotest without Rails
Autotest is a gem (well, technically ZenTest is a gem that includes autotest). But seriously, autotest is a gem! I can’t write code without it anymore. It has become my coding security blanket.
I started going through withdrawal last night while I was working on a Ruby library because autotest doesn’t work out of the box with plain ol’ Ruby projects. It assumes you’re using one of the Ruby web frameworks.
Here’s how to remedy that.
Aizatto shows us how to use autotest with your Rails plugins and RSpec. That’s a great start, but unfortunately, not all of my projects use RSpec (yet), and not all of them are Rails plugins.
To make autotest work with
Test::Unit, we need to tell it how to map files to their tests. Here is a simple mapping that maps each ruby file in
lib/ to the a corresponding test
test/*_test.rb. For example,
lib/foo/bar.rb would map to to a test in
We have the mapping, now all we need to do is tell autotest about it.
Throw both of those files into a
autotest/ directory in your plain ol’ Ruby project and autotest should just work for you.
Extra credit: Make it work with RSpec on plain ol’ Ruby projects.