Watchr: A Flexible, Generic Alternative to AutoTest
Watchr is a continuous-testing tool by Martin Aumont in the vein of Autotest (part of the ZenTest package).
At its heart, Watchr basically watches any (or all!) of your project's files, then executes arbitrary Ruby code of your choice when things change. Watchr configuration takes such a form:
watch('pattern') { |match_data_object| command_to_run }
For example, to produce Autotest-like functionality, you'd just specify Watchr to run the tests whenever a test or some library code changes, like this (taken from Martin's blog post):
watch('test/test_.*.rb') { |md| system "ruby #{md[0]}"} watch('lib/(.*).rb') { |md| system "ruby test/test_#{md[1]}.rb"}
...but Watchr can be used for much more than just testing. You could use it to automatically generate documentation, build your gem or any other tasks that you can script in Ruby.
To get started with Watchr, just install the gem (from Gemcutter), and run the watchr command from your project root, passing the location of the configuration script:
$ gem install watchr --source=http://gemcutter.org $ cd to/your/project/root $ watchr path/to/script
The source and some documentation (including example scripts) is available on Github, and you can read more on Martin's blog too.
If an even more simplistic route appeals to you, Ruby Inside's editor, Peter Cooper, has a basic Rake task that can run a script of your choice when files change within a project.
September 24, 2009 at 12:19 pm
Cool.
Wait, what?
September 24, 2009 at 12:28 pm
Good catch, Kerry - I've fixed it up.
September 24, 2009 at 1:04 pm
oops :)
Yeah I agree the Watchr docs don't make it too clear either. It doesn't depend on rubygems as in if you install Watchr with rip (rip install git://github.com/mynyml/watchr.git), rubygems will never be loaded. Just trying to be a good gemizen. Though of course, a gem is still provided for convenience.
September 24, 2009 at 3:06 pm
But who watches the Watchr?
September 24, 2009 at 4:00 pm
Regarding the rubygems thing - I was trying to express what Martin explains above. i.e. you don't need rubygems if you don't want it.