Getting Autotest to run on OS X

Jan 14, 2011 16:06 · 234 words · 2 minute read autotest bdd rails rspec ruby tdd testing

Autotest is a Gem that does what it says on the tin - runs your RSpec test automatically. If you’re using a Mac, you can also use autotest-growl to get it to display Growl notifications, and autotest-fsevent to get it to watch the filesystem and trigger the tests when changes are made to the spec files.

Installing it is a bit fiddly - this is what works for me, based on a bit of help from Jon Rowe:

# Install the autotest-standalone, autotest-fsevent and autotest-growl gems:

gem install autotest-standalone
gem install autotest-fsevent
gem install autotest-growl

# Create a .autotest file in the root of the Rails project (or in your home directory if you want the settings to take effect globally) and update it with this:

  require 'autotest/fsevent'
  require 'autotest/growl'
rescue LoadError

Autotest.add_hook :initialize do |at|

  at.add_mapping(/^spec\/**\/*_spec\.rb$/, true) { |filename, _|

  at.add_mapping(/^spec\/support\/.*\.rb$/, true) { |_, _|

  at.add_mapping(/^app\/(.*)\.rb$/, true) { |_, m|


# Run autotest:

bundle exec autotest

# If you want it to run Cucumber features as well, use:

 AUTOFEATURE=true bundle exec autotest

The autotest-fsevent gem responds to filesystem triggers, so every time you save a spec or feature file, it will trigger autotest to run the test suite. Then the autotest-growl gem will get Growl to popup a notification of the test results. It’s a handy thing to have running in the background.