The usual autotest workflow goes something like this:

Sometimes though, you want autotest to just ignore most of your specs and focus on a few specs.

Last week, while Kevin, Rick, and Yossef (OG) were here, they shared an autotest tweak that does exactly that.

The tweak allows you to specify a regular expression to limit the files which autotest watches; for example, to autotest only files matching *user*.rb you would start autotest like so (atest is an alias):

% atest user

Here is the (lightly modified) code to do this; in your .autotest file add:

 1if ENV['AUTOTEST'] and not ENV['AUTOTEST'].empty?
 2  only_these_files_re =['AUTOTEST'])
 4  Autotest.send(:alias_method, :real_find_files, :find_files)
 5  Autotest.send(:define_method, :find_files) do |*args|
 6    real_find_files.reject do |k, v|
 7      !only_these_files_re.match(k)
 8    end
 9  end

And in your .bash_profile add:

# Autotest
function fn_autotest() {
  AUTOTEST=$1 autotest
alias atest='fn_autotest'

Now use the alias to invoke autotest. For standard autotest behavior:

% atest

To limit what autotest is watching, pass a regular expression (which can be a simple string):

% atest user.*html
blog comments powered by Disqus