This post originated from an RSS feed registered with Ruby Buzz
by Jamie Hill.
Original Post: Using autotest when developing Rails plugins
Feed Title: The Lucid
Feed URL: http://feeds.feedburner.com/thelucid
Feed Description: Lightweight ramblings and tips on Ruby and Rails.
I am a great fan of ZenTest’s ‘autotest’ tool and use it continuously whilst developing Rails apps. Up until now I’d not found a way to use autotest while developing plugins.
The problem
After some digging around in the ZenTest source, it turns out that autotest looks for files that are prefixed with test_ however the standard convention in Rails is to use a suffix e.g. base_test.rb. You could simply prefix your tests instead of using suffixes and modify the test file pattern in the Rakefile, however this feels wrong.
I noticed that autotest looks for a .autotest file in the current directory before looking in the home directory meaning that getting autotest to run for plugins is surprisingly simple.
The solution
Create an .autotest file in the root of the plugin directory containing the following:
You can now cd into the plugin dir, run autotest and all works as it does in a Rails app1. Also as this file loads the .autotest file in the home directory, any Growl notifiers etc. setup there will all work fine.
1 The only difference is that all tests are re-loaded when a test file is saved. This is not an issue for the majority of plugins, if it is, then it’s probably a sign that the tests need optimising.