Force autotest to load all your application files
I was having a problem where autotest was not picking up changes to one of my models, and therefore not running my specs when I was saving changes. It was however picking up the filesystem event, which was odd. All I was getting was the following…
# Waiting since 2011-03-08 11:49:33 .. .. # Waiting since 2011-03-08 11:51:53 .. ..
To fix this, create an autotest folder in your application root. Then create a discover.rb file in the new autotest folder with the following content:
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
Autotest.add_hook(:initialize) do |at|
at.add_mapping(%r%^(models|controllers|routing|views|helpers|mailers|requests|lib)/.*rb$%) do |filename, _|
filename
end
end
What we’re doing here is adding an autotest hook which creates a new file mapping. This will ensure that all files in the folders mathcing our regular expression will be monitored by autotest, thereby firing the relevant specs when you maek an update to either the spec or the model/controller/view etc.
Happy testing.