News & Views.

The latest news, web designs and digital projects happening at Storm.

Sharing is caring:

Stop autotest continuously re-running your Rails tests

Adam Pope Profile Image

Adam Pope
September 16, 2011

I’ve been getting up to speed with writing unit tests for Rails applications today.  My setup currently consists of RSpec tests being automatically run by autotest when I save a file.  This is a really nice workflow as you get instant feedback on failing tests.  Couple that with the autotest-growl gem to receive Growl notifications on failure and you’ve got a pretty funky setup.

However, autotest decided it wanted to re-run my tests over and over again, even if I hand’t saved a file in my project.  This had me very confused for quite a while until some Googling led me to ‘autotest -v’ which shows you which files had changed.  The culprit: test.log.

Excluding log files from autotest

The workaround for this is pretty simple.  In your project root directory create a .autotest file.  Inside, put

Autotest.add_hook :initialize do |autotest|
  %w{.git .svn .hg .DS_Store ._* vendor tmp log doc}.each do |exception|
    autotest.add_exception(exception)
  end
end

require "autotest/growl"
require "autotest/fsevent"

That little snippet will exclude a bunch of files that you don’t want autotest to care about. The two requires at the bottom are needed for the awesome Growl integration :)