<?xml version="1.0" encoding="UTF-8"?>
<post>
  <id type="integer">68</id>
  <title>Scoping autotest on the fly</title>
  <content>
<p>Recently, I refactored some code that broke stuff all over the place, and autotest started spitting and re-running far too many failing specs for me to make much sense of it.  I wanted a bit more control over what was watched and run.</p>

<p>Google to the rescue &#8211; it turned up <a href="http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest">this post</a> by David Chelimsky that describes how to limit autotest&#8217;s scope to certain directories.</p>

<pre><code>$ autotest models
$ autotest spec/lib lib
</code></pre>

<p>Nice.  But I was jumping around quite frequently, and in many cases, I wanted to limit the scope to single files.  Remembering <code>autotest/menu.rb</code>, I whipped up a quick module that let you reset the scope without having to restart autotest.</p>

<pre><code>$ autotest
...
^C
1. Quit
2. Continue
3. Restart
4. Re-scope
&gt; 4
New scope? models
...
</code></pre>

<p>Sweet.  In addition to recognizing some magic words &#8211; models, controllers, views, lib, all &#8211; it also accepts a space-separated list of directories and files.  As a final nicety, it also automatically adds the matching spec for models, controllers and libs, since autotest needs to know about both tests and implementations:</p>

<pre><code># Will add "app/models/user.rb" and "spec/models/user_spec.rb"
New scope? app/models/user.rb
</code></pre>

<p>That&#8217;s all.  The file is available here: <a href="http://blog.forsamurai.com/files/scope_menu.rb">scope_menu.rb</a></p>  </content>
  <published-on type="datetime">2008-07-02T04:13:33Z</published-on>
  <created-on type="datetime">2008-07-02T04:13:33Z</created-on>
  <updated-on type="datetime">2008-07-02T04:13:33Z</updated-on>
</post>
