$cake = "/Applications/MAMP/bin/php5/bin/php /Applications/MAMP/htdocs/yourProject/cake/console/cake.php" watch('app/(models|controllers)/(.*).php') { |m| test_changed_model_or_controller(m[0]) } watch('app/tests/cases/(models|controllers)/(.*).test.php') { |m| test_changed_test_case(m[0]) } watch('app/config/(.*).php') { |m| test_app() } watch('app/(app_controller|app_model).php') { |m| test_app() } def test_changed_model_or_controller(file) type = file.split('/')[1] name = file.split('/')[2].split('.')[0] run "#{$cake} testsuite app case #{type}/#{name}" end def test_changed_test_case(file) type = file.split('/')[3] name = file.split('/')[4].split('.')[0] run "#{$cake} testsuite app case #{type}/#{name}" end def test_app() run "#{$cake} testsuite app all" end def run(cmd) puts(cmd) result = `#{cmd}` growl result rescue nil puts result end def growl(message) message = message.split('---------------------------------------------------------------')[3].split('Time taken by tests')[0] growlnotify = `which growlnotify`.chomp image = message.include?('fails') ? "~/.watchr_images/failed.png" : "~/.watchr_images/passed.png" options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}'" system %(#{growlnotify} #{options} &) end #source 1: http://gist.github.com/276317 #source 2: http://bjhess.com/blog/2010/2/23/setting_up_watchr_and_rails/ #source 3: http://www.rubyinside.com/watchr-generic-autotest-alternativ-2511.html #source 4: http://github.com/mynyml/watchr/blob/master/README.md #source 5: http://book.cakephp.org/view/863/Running-tests-in-the-Command-Line