<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>David Chelimsky: limiting scope of autotest</title>
    <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>on software in process and practice</description>
    <item>
      <title>limiting scope of autotest</title>
      <description>&lt;p&gt;If you use &lt;a href="http://zentest.rubyforge.org/ZenTest/classes/Autotest.html"&gt;autotest&lt;/a&gt; with &lt;a href="http://rspec.info"&gt;rspec&lt;/a&gt; or test/unit, you&amp;#8217;ve probably had this experience (or one like it):&lt;/p&gt;


	&lt;p&gt;You want to add some new behaviour to a model object, so you write a spec, watch it fail, make it pass, and then wait until the entire spec suite runs. Even if you&amp;#8217;ve got a fast-running suite, this can be painful sometimes.&lt;/p&gt;


	&lt;p&gt;Wouldn&amp;#8217;t it be great if you could limit the scope of what directories autotest observes?  Well it turns out that you can! Recent releases of ZenTest include a find_directories attribute on the autotest object. Just add this to your .autotest file:&lt;/p&gt;


&lt;pre&gt;
Autotest.add_hook :initialize do |at|
  unless ARGV.empty?
    at.find_directories = ARGV.dup
  end
end
&lt;/pre&gt;

	&lt;p&gt;and then you can say:&lt;/p&gt;


&lt;pre&gt;
autotest app/models spec/models
&lt;/pre&gt;

	&lt;p&gt;and it will only observe those directories. This is nice and flexible, but I find that most of the time I&amp;#8217;m wanting pairs like that: app/models and spec/models, or app/views/accounts and spec/views/accounts. In that case, I&amp;#8217;d really like to just say:&lt;/p&gt;


&lt;pre&gt;
autotest models
&lt;/pre&gt;

	&lt;p&gt;To accomplish that you can do this to the hook instead:&lt;/p&gt;


&lt;pre&gt;
Autotest.add_hook :initialize do |at|
  unless ARGV.empty?
    at.find_directories = ["spec/#{ARGV.first}","app/#{ARGV.first}"]
  end
end
&lt;/pre&gt;

	&lt;p&gt;Want the best of both worlds? Try this:&lt;/p&gt;


&lt;pre&gt;
Autotest.add_hook :initialize do |at|
  unless ARGV.empty?
    at.find_directories = ARGV.length == 1 ? ["spec/#{ARGV.first}","app/#{ARGV.first}"] : ARGV.dup
  end
end
&lt;/pre&gt;

	&lt;p&gt;The only limitation of this is that it&amp;#8217;s based on directories, not files. Once in a while, when I&amp;#8217;m bootstrapping a new object, I&amp;#8217;ll keep the examples and the implementation in the same file until I&amp;#8217;ve got things fleshed out a bit the object is ready to play nice with others. In that case, I might like to just point autotest to that one file. I started working on a patch for this for ZenTest, but I&amp;#8217;m not sure it&amp;#8217;s worth the extra effort. What do you think?&lt;/p&gt;


	&lt;p&gt;Regardless &amp;#8211; happy auto-exemplifying!&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 02:07:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:7b63be47-39a5-428f-9a6f-13e2f1542a04</guid>
      <author>David</author>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest</link>
      <category>rspec</category>
      <category>bdd</category>
      <category>autotest</category>
    </item>
    <item>
      <title>"limiting scope of autotest" by Chris Anderson</title>
      <description>&lt;p&gt;David &amp;#8211; you may be right.&lt;/p&gt;


	&lt;p&gt;I remember having some conversations and reading some threads where the upshot was &amp;#8220;if you&amp;#8217;re test suite is slow the problem is your tests&amp;#8221; which is often the case. That and being frustrated by the changing plugin API are probably what gave me the impression that Autotest is opinionated software. I definitely don&amp;#8217;t want to put words in Ryan&amp;#8217;s mouth, so perhaps it&amp;#8217;s my mistaken impression.&lt;/p&gt;


	&lt;p&gt;Anyway, autotest is nearly the most important piece of gear in my kit, and if I&amp;#8217;m working, it&amp;#8217;s running.&lt;/p&gt;


	&lt;p&gt;@steve it should be in your ~ directory&lt;/p&gt;


&lt;pre&gt;
cat ~/.autotest
&lt;/pre&gt;

	&lt;p&gt;If it&amp;#8217;s not, you can create it.&lt;/p&gt;</description>
      <pubDate>Fri, 14 Mar 2008 13:21:13 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:f552d7fa-b766-4d55-b95c-659d273bc443</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-464</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by steve</title>
      <description>&lt;p&gt;help a noob&amp;#8212;where is the .autotest file (on Mac OS X)&lt;/p&gt;</description>
      <pubDate>Fri, 14 Mar 2008 12:37:26 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:6a78d1b0-1d7c-46f2-84be-030d38a99cc7</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-463</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by David Chelimsky</title>
      <description>&lt;p&gt;@chris &amp;#8211; what gives you the idea that ZenSpider hates the idea of scoping autotest? He actually invited me to submit a patch for this before I realized it was just as easy to do it .autotest as described above :)&lt;/p&gt;</description>
      <pubDate>Fri, 14 Mar 2008 10:25:41 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:33f8540c-b975-4064-ab44-1ada111b4b8f</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-462</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Anny</title>
      <description>&lt;p&gt;PS How can I get that little cloud before the comment link on the blog? Is that Haloscan and Blog template?;&lt;/p&gt;</description>
      <pubDate>Thu, 13 Mar 2008 05:49:03 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:5cde9947-5f91-40be-9950-ec6139aa0a70</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-461</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Chris Anderson</title>
      <description>&lt;p&gt;David,&lt;/p&gt;


	&lt;p&gt;My setup uses a regex which allows autotest only to run the files that match it. this makes limited scoping to a set of models really easy.&lt;/p&gt;


	&lt;p&gt;usage:&lt;/p&gt;


	&lt;p&gt;AUTOTEST=&amp;#8217;post|comment&amp;#8217; autotest&lt;/p&gt;


	&lt;p&gt;now autotest will only look at files that match &amp;#8216;post&amp;#8217; or &amp;#8216;comment&amp;#8217;.&lt;/p&gt;


	&lt;p&gt;my implementation is crappy though &amp;#8211; I just shoved some code into my copy of the autotest gem.&lt;/p&gt;


	&lt;p&gt;from ZenTest 3.9.1 autotest.rb line 360:&lt;/p&gt;


&lt;pre&gt;
        # my horrible hack
        order = order.select do |k,v| 
           (ENV['AUTOTEST'] and ! ENV['AUTOTEST'].empty?) ?   
              Regexp.new(ENV['AUTOTEST']).match(k) : true
        end.uniq
&lt;/pre&gt;

	&lt;p&gt;ZenSpider seems to hate the idea of scoping autotest, so I doubt we&amp;#8217;ll ever get this functionality built in. I don&amp;#8217; think there&amp;#8217;s a hook you can use for this anymore, at least I didn&amp;#8217;t see anything there in the code that looks promising.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 19:39:04 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:17090349-b383-49c6-bedd-a276ecadb613</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-460</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Chris Anderson</title>
      <description>&lt;p&gt;David,&lt;/p&gt;


	&lt;p&gt;My setup uses a regex which allows autotest only to run the files that match it. this makes limited scoping to a set of models really easy.&lt;/p&gt;


	&lt;p&gt;usage:&lt;/p&gt;


	&lt;p&gt;AUTOTEST=&amp;#8217;post|comment&amp;#8217; autotest&lt;/p&gt;


	&lt;p&gt;now autotest will only look at files that match &amp;#8216;post&amp;#8217; or &amp;#8216;comment&amp;#8217;.&lt;/p&gt;


	&lt;p&gt;my implementation is crappy though &amp;#8211; I just shoved some code into my copy of the autotest gem.&lt;/p&gt;


	&lt;p&gt;from ZenTest 3.9.1 autotest.rb line 360:&lt;/p&gt;


&lt;pre&gt;
        # my horrible hack
        order = order.select do |k,v| 
           (ENV['AUTOTEST'] and ! ENV['AUTOTEST'].empty?) ?   
              Regexp.new(ENV['AUTOTEST']).match(k) : true
        end.uniq
&lt;/pre&gt;

	&lt;p&gt;ZenSpider seems to hate the idea of scoping autotest, so I doubt we&amp;#8217;ll ever get this functionality built in. I don&amp;#8217; think there&amp;#8217;s a hook you can use for this anymore, at least I didn&amp;#8217;t see anything there in the code that looks promising.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 19:38:46 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:f5d973d8-bac7-4302-9ecb-332eae4e6adf</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-459</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by David Chelimsky</title>
      <description>&lt;p&gt;@Jean-Michel &amp;#8211; yes, I too come from the wonderful world of java tools and I do long for the day that my language of choice has the same level of TDD/Refactoring support. It&amp;#8217;s moving along. NetBeans has some cool features now (including code completion for RSpec!) but it&amp;#8217;s got a way to go.&lt;/p&gt;</description>
      <pubDate>Thu, 06 Mar 2008 22:48:34 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:239cd2fe-9638-49be-bc0b-f583651c2a03</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-458</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by http://www.21croissants.com</title>
      <description>&lt;p&gt;&lt;strong&gt;David said:&lt;/strong&gt;
@Jean-Michel – the “one file” thing is only cases in which I’m  working on something very focused that has no incoming  dependencies yet. So I’d fire up autotest, restricting it to the  one file (or one spec and one implementation file), and get  that working right, and then restart autotest with the full  suite (or just the directories for the encompassing component).&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Jean-Michel replies:&lt;/strong&gt;
Now I understand better your needs and your tip . I can&amp;#8217;t live without Autotest either :-)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;David said:&lt;/strong&gt;
As for execute_latest_failure – seems like that would have to be re-written all the time, as it names a specific example. Or am I missing something?&lt;/p&gt;


&lt;strong&gt;Jean-Michel replies:&lt;/strong&gt;
Yes. In fact, I was a bit ashamed of my hack. This is the full code:
&lt;pre&gt;
def execute_latest_failure
    "" 
#    "-e 'CommunityController (when the session has been resetted) AJAX add_country should not throw exception'" 
  end
&lt;/pre&gt;

	&lt;p&gt;So every time, I need Autotest to execute the &amp;#8220;ONE&amp;#8221; spec I am working on, I commment the first line of execute_latest_failure and uncomment the second line &amp;#8230; Pathetic I know&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;David said:&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;As for autotest not recognizing new files and new methods, this is new behaviour since the recent releases. From what I can tell this does not happen in with test/unit, so I need to figure out what&amp;#8217;s going on there.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Jean-Michel replies:&lt;/strong&gt;
Sorry about the misunderstanding. I meant: as I write the spec before the code, it&amp;#8217;s normal that the spec failed with &amp;#8220;NoMethodError&amp;#8221;. When I save my spec, it triggers Autotest and the spec fails. Then, I will add the new method in the class &amp;#8230;&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;David said:&lt;/strong&gt;
I think autotest is the wrong place for adding code to your code. That should be in the editor, in my opinion. This is the sort of help java developers get from tools like eclipse and IntelliJ out of the box that could make a Ruby developer&amp;#8217;s life a bit easier, but putting it in autotest makes autotest a bit too invasive IMO.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Jean-Michel replies:&lt;/strong&gt;
At the end of the day, you&amp;#8217;re right, this is definitely a feature that IDEs should provide.&lt;/p&gt;


	&lt;p&gt;But Autotest code seems to be easier to plugin. I think I will play with it and try to implement this feature. I was addicted to it when I was a java developper working with Eclipse: the method does not exist? =&amp;gt; CTRL+1 triggerred a quick fix and RETURN was suggesting to add the missing method. It was a very productive way of TDD :-)
What is your background?&lt;/p&gt;</description>
      <pubDate>Thu, 06 Mar 2008 13:30:49 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:fdef47e9-5efc-4e6d-990d-34971183b551</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-457</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by kat</title>
      <description>&lt;p&gt;I&amp;#8217;ve been having the same experience as Niel &amp;#8211; when going from red to green it doesn&amp;#8217;t run the entire suite anymore.&lt;/p&gt;</description>
      <pubDate>Thu, 06 Mar 2008 12:41:17 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:84694b0b-a9dc-4ac7-b37a-4724cdb02add</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-456</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by David Chelimsky</title>
      <description>&lt;p&gt;@Neil &amp;#8211; I don&amp;#8217;t find that funny :)&lt;/p&gt;


	&lt;p&gt;Seriously &amp;#8211; I&amp;#8217;m having a different experience than you are.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 15:41:08 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1beff8c8-e46e-40ec-832c-9bb4aea76265</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-455</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Neil Wilson</title>
      <description>&lt;p&gt;@David,&lt;/p&gt;


	&lt;p&gt;Same with a red green cycle.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 14:27:10 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:595eb11b-4840-4907-802c-ba72a60d5d32</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-454</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Neil Wilson</title>
      <description>&lt;p&gt;@David,&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s funny, because autotest -f doesn&amp;#8217;t do that here. If I touch a file after firing it up it just runs that spec and nothing else.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m using 3.9.1&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 14:10:21 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ca95caf5-4dc1-4f77-b2d4-0f43636f1c76</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-453</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by JJ</title>
      <description>&lt;p&gt;Good codes. So far i have no bugs with them.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 10:37:37 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:eed564c8-fe2b-4e5b-a47c-61342904db30</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-452</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by David Chelimsky</title>
      <description>&lt;p&gt;@Neil &amp;#8211; the &amp;#8216;-f&amp;#8217; option makes it so autotest does not run everything until you change something. As soon as you make a change it does its normal thing: as soon as you get red followed by green, it&amp;#8217;s going to run the whole suite. I want to make it so it runs a subset of the suite to keep things moving faster.&lt;/p&gt;


	&lt;p&gt;@Jean-Michel &amp;#8211; the &amp;#8220;one file&amp;#8221; thing is only cases in which I&amp;#8217;m working on something very focused that has no incoming dependencies yet. So I&amp;#8217;d fire up autotest, restricting it to the one file (or one spec and one implementation file), and get that working right, and then restart autotest with the full suite (or just the directories for the encompassing component).&lt;/p&gt;


	&lt;p&gt;As for execute_latest_failure &amp;#8211; seems like that would have to be re-written all the time, as it names a specific example. Or am I missing something?&lt;/p&gt;


	&lt;p&gt;As for autotest not recognizing new files and new methods, this is new behaviour since the recent releases. From what I can tell this does not happen in with test/unit, so I need to figure out what&amp;#8217;s going on there.&lt;/p&gt;


	&lt;p&gt;I think autotest is the wrong place for adding code to your code. That should be in the editor, in my opinion. This is the sort of help java developers get from tools like eclipse and IntelliJ out of the box that could make a Ruby developer&amp;#8217;s life a bit easier, but putting it in autotest makes autotest a bit too invasive IMO.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 09:27:31 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:415668dd-20e9-4a8a-9b89-2ddd3d5be1c4</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-451</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Matt Darby</title>
      <description>&lt;p&gt;Great tip! I&amp;#8217;ve wished for this functionality for months!&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 08:37:24 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e3bc379f-5ee3-4abf-bcbd-58f7e7ecc185</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-450</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by http://www.21croissants.com</title>
      <description>&lt;p&gt;Nice trick David!&lt;/p&gt;


	&lt;p&gt;I am not sure using autotest to point to only one file would have an added value: I really like when autotest detects a regression in a class which has nothing to do with the class I am specing because my changes had unexpected side effects &amp;#8230;&lt;/p&gt;


	&lt;p&gt;However, some of my specs are running slowly (I am not using mocks everywhere yet!) so I monkey patched RSpec with the following hack so Autotest only runs the latest failed spec:&lt;/p&gt;


&lt;pre&gt;
class Autotest::Rspec &amp;lt; Autotest

  def make_test_cmd(files_to_test)
    return "#{ruby} -S #{spec_command} #{add_options_if_present} #{execute_latest_failure} #{files_to_test.keys.flatten.join(' ')}" 
  end

  def execute_latest_failure
    "-e 'CommunityController (when the session has been resetted) AJAX add_country should not throw exception'" 
  end

&lt;/pre&gt;

	&lt;p&gt;Doing that, Autotest could run that only spec in 5s only instead of almost 45s for my CommunityControllerSpec!!!&lt;/p&gt;


	&lt;p&gt;Do you think I should propose a patch?&lt;/p&gt;


Another thought. As I am working in a TDD Style, I always write the spec first and when I add a new method to a class, Autotest first fails with:
&lt;pre&gt;
NoMethodError in 'MyClassUnderBDD should  a_long_descriotion)'
undefined method 'the_method_just_added_coz_I_write_specs_first'
&lt;/pre&gt;

	&lt;p&gt;Which is fair enough ;-) This was done on purpose.&lt;/p&gt;


	&lt;p&gt;What do you think about Autotest asking you if you want to add the skeleton of the new method automatically to class under test? It would save me so many copy-pasted!!!&lt;/p&gt;


	&lt;p&gt;Jean-Michel Garnier&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 07:57:52 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8ec95144-d19e-4572-9005-b1a59e3ff340</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-448</link>
    </item>
    <item>
      <title>"limiting scope of autotest" by Neil Wilson</title>
      <description>Don&amp;#8217;t you just do 
&lt;pre&gt;
autotest -f
&lt;/pre&gt;

	&lt;p&gt;to skip the full run when autotest starts. Then it just runs the files that change.&lt;/p&gt;


	&lt;p&gt;Or did I not understand the question?&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 04:54:13 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f8838b35-0c5f-4694-bcd7-706a81baaee2</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/03/05/limiting-scope-of-autotest#comment-447</link>
    </item>
  </channel>
</rss>
