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, _|

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s