Autotest Integration

Arsk edited this page Oct 21, 2013 · 15 revisions

For rspec2, see

See first.

RSpec wraps the autotest command with an autospec command

rspec overrides the existing mappings in autotest/rspec.rb

rspec-rails overrides them further in autotest/rails_rspec.rb

Autotest will load ~/.autotest and ./.autotest (in that order) after it loads up RSpec’s autotest subclasses, so you can further modify things in those files. For example, if you want to clear existing mappings, and add new mappings of your own, while also ignoring any temp file created by cucumber, you get something like this:

Autotest.add_hook(:initialize) {|at|
  at.add_exception %r{^\.git}  # ignore Version Control System
  at.add_exception %r{^./tmp}  # ignore temp files, lest autotest will run again, and again...
  #  at.clear_mappings         # take out the default (test/test*rb)
  at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|

You may also have an #add_mapping for integration specs :

Autotest.add_hook :initialize do |at|
  at.add_mapping(%r%^spec/(integration)/.*rb$%) {|filename, _|

The nil makes sure that other :initialize hooks get executed (in the case of add_mapping or add_exception, nil is already returned)
Very relevant if you have both ~/.autotest and .autotest

I run autotest/spec like this

$ RUBYLIB=./lib RUBYOPT=-rubygems AUTOFEATURE=true autospec

but you may find this to be good enough:

$ RUBYLIB=./lib RUBYOPT=-rubygems autotest

Though autotest/spec will rerun when you modify .autotest, it will not execute the :initialize hook, you have to press ^C twice and restart autotest/spec.

Also see Cucumber’s Autotest Integration

Enable growl notifications (optional, for Mac OSX)

Install the autotest-growl gem:

$ sudo gem install autotest-growl

In your ~/.autotest or ./.autotest file, add:

require 'autotest/growl'

For more details, see getting-started-with-autotest

RSpec 2 Notes

For RSpec 2 there is no need to load the redgreen gem, since RSpec 2 does its own coloring.
Also don’t use RSPEC=true. You can use AUTOFEATURE=false to disable auto-running cucumber features.