Automating Rails Testing with autotest
Lee asked the proverbial question ‘When do I test’ … and then provided the answer http://whendoitest.com/
If you click the answer, you will see there is a short video,
watching the video lead me to ZenTest (autotest) … Which I happily integrated into my project painlessly in a few minutes.
This is a GREAT plugin for Rails development… Continuos Testing .. Who Knew?
I googled … and came across a nice little addition to the autotest gem… colors in the console via RedGreen (also a gem).
So now, my test run anytime I change a file (small issue with migrations) and any failures visually stand out because of the Red
For any developers out there that want to do I I do, (not sure why you would want to subject yourself to the sadism, but it’s your choice)
To Install RedGreen:
<code>> sudo gem install redgreen</code>
To Install Autotest:
<code>> sudo gem install ZenTest </code>
I think the windows people will have to use rails gem install vs. sudo gem install.
I then added the following to a file ~/.autotest (found online)
<code>
Autotest.send(:alias_method, :real_make_test_cmd, :make_test_cmd)
Autotest.send(:define_method, :make_test_cmd) do |*args|
real_make_test_cmd(*args).sub(‘test/unit’, %[rubygems -e "require 'redgreen'"])
end
</code>
To execute, just run autotest from the console, the first time through all tests will be performed, and the console will sit and wait for a file to be saved (I have my TextMate set to save on lost focus). The uber neat thing is that autotest knows which unit tests to run (based on the file being saved) and only executes the tests that would be affected.
Pretty sweet.

