Introduction
I have a webapp written in Symfony 1.4 for which I have unit tests. I would like my file system to be continuously monitored so that whenever I edit files in my Symfony project, my unit tests are run. That way, if I break any tests during development, I will instantly know about it. After some googling around about the problem, I found these blog posts
Autotesting with watchr, growl and PHPUnit
CakePHP: Autotest using Watchr
I take these posts a step further in that I further develop the watchr.rb script to keep track of individual test files run and to print their error messages, if any. That way, I can know exactly which test failed. I also show how to use launchd.plists to automatically start watchr when you log into to your Mac.
watchr
I have no previous programming experience with Ruby and was looking for a small project to get acquainted with it. Working with the watchr seemed like a perfect way to get my toes wet. watchr is a command line program is run with one argument, it’s config file.
$ watchr path/to/script.rb
In the script there is a call to the function, watch, which tells the program which files to monitor and what to do when it sees a file change.
Here is an example script which monitors all php files in the dir that contains my model files, ‘lib/model/doctrine’ and simply prints the name of the file which was modified to stdout.
watch('lib/model/doctrine/(.*).php') { |m| code_changed(m[0]) }
def code_changed(file)
puts(file)
end