<?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: RSpec-1.1.2 and ZenTest-3.8.0</title>
    <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>on software in process and practice</description>
    <item>
      <title>RSpec-1.1.2 and ZenTest-3.8.0</title>
      <description>&lt;p&gt;The &lt;a href="http://rspec.info"&gt;RSpec-1.1.2&lt;/a&gt; release includes changes to keep RSpec compatible with autotest in &lt;a href="http://zentest.rubyforge.org/ZenTest/"&gt;ZenTest-3.8.0&lt;/a&gt;. This new ZenTest release boasts an improved cascading configuration model that works well for subclasses (like those that ship with RSpec) &lt;strong&gt;and&lt;/strong&gt; allows users to override the mappings of specs (or tests) to code as well as the list of files that get ignored by autotest.&lt;/p&gt;


	&lt;p&gt;To support this, Autotest now loads the following files in the following order:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
Autotest
AutotestSubClass
~/.autotest
./.autotest
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This allows RSpec (or any other library) to override defaults set in &lt;code&gt;Autotest&lt;/code&gt;, and then provides users both generic (~/.autotest) and project specific (./.autotest) control over the mappings and exceptions.&lt;/p&gt;


	&lt;p&gt;How can you take advantage of this?&lt;/p&gt;


	&lt;p&gt;When autotest begins to run, it calls its &lt;code&gt;:initialize&lt;/code&gt; hook. This hook is exposed by the &lt;code&gt;add_hook&lt;/code&gt; method. You can use this to access the mappings and exceptions using the following methods on Autotest:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
clear_mappings()
add_mapping(regexp, proc)
remove_mapping(regexp)

clear_exceptions()
add_exception(string)
remove_exception(string)
&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;add_mapping&lt;/h4&gt;


	&lt;p&gt;The &lt;code&gt;add_mapping&lt;/code&gt; method adds a key/value pair to a hash that maps regexps to procs. Whenever autotest senses that a file is touched, it looks for the regexp that matches the file name and the runs all the files returned by the associated proc.&lt;/p&gt;


	&lt;p&gt;Imagine you&amp;#8217;re working on a shopping cart app. You have some currency conversion behaviour in a &lt;code&gt;Product&lt;/code&gt; model that you&amp;#8217;d like to extract to an &lt;code&gt;acts_as_currency&lt;/code&gt; plugin, and you want autotest to observe the process. You might add a mapping like this to .autotest:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
Autotest.add_hook :initialize do |at|
  at.add_mapping(%r%^plugins/acts_as_currency/lib/.*\.rb$%) {
    at.files_matching %r%^spec/models/product_spec\.rb$% +
    at.files_matching %r%^plugins/acts_as_currency/spec/.*_spec\.rb$%
  }
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In this case, a change to any of the files in the plugin&amp;#8217;s lib directory would cause all the plugins specs to run, as well as the spec for the &lt;code&gt;Product&lt;/code&gt; model.&lt;/p&gt;


	&lt;h4&gt;add_exception&lt;/h4&gt;


	&lt;p&gt;The &lt;code&gt;add_exception&lt;/code&gt; method adds paths to a list of paths that Autotest ignores.&lt;/p&gt;


	&lt;p&gt;I like to run autotest in verbose mode (&lt;code&gt;autotest -v&lt;/code&gt;) because it tells me when I change a file that it doesn&amp;#8217;t know what to do with. The drawback is that it wants to tell me every time I commit because files in the .svn/.hg/.git directories change. So I&amp;#8217;ve got these all listed as exceptions in my ~/.autotest file, along with assorted others:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
Autotest.add_hook :initialize do |at|
  %w{.svn .hg .git}.each {|exception|at.add_exception(exception)}
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Note that autotest compiles this list to a Regexp with no anchors, so .hgignore and .gitignore would also get ignored in this case.&lt;/p&gt;


	&lt;h4&gt;Cascading config and granular control&lt;/h4&gt;


	&lt;p&gt;One of the coolest changes in ZenTest-3.8.0 is that autotest loads both ~/.autotest and ./.autotest. So now you can have the hooks you like on every project (like growl notifation) all in one place and still have project specific settings.&lt;/p&gt;


	&lt;p&gt;This also allows you to set up global mappings/exceptions and modify them at the project level. See &lt;a href="http://zentest.rubyforge.org/ZenTest/classes/Autotest.html"&gt;Autotest&amp;#8217;s RDoc&lt;/a&gt; for more info.&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jan 2008 01:15:55 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2db4938a-328f-473c-bbdc-0ec0e80ef56f</guid>
      <author>David</author>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0</link>
      <category>rspec</category>
      <category>autotest</category>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Luis Lavena</title>
      <description>&lt;p&gt;@Tick: you should try setting the environment variable HOME.&lt;/p&gt;


	&lt;p&gt;Try with &lt;code&gt;%HOMEDRIVE%%HOMEPATH%&lt;/code&gt;
(in System Properties, Advanced, Environment Variables).&lt;/p&gt;


	&lt;p&gt;That will solve the expansion of &lt;code&gt;"~"&lt;/code&gt; on Windows.&lt;/p&gt;


	&lt;p&gt;HTH,&lt;/p&gt;


	&lt;p&gt;Luis&lt;/p&gt;</description>
      <pubDate>Tue, 22 Jan 2008 21:31:25 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:75c9c1a0-22f6-4d9b-b0d8-1c06583b691d</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-424</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Tick</title>
      <description>&lt;p&gt;I will.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Jan 2008 16:43:12 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:41bd7423-3674-4d2d-84ca-5c45c1f5112d</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-422</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by David Chelimsky</title>
      <description>&lt;p&gt;@Tick &amp;#8211; you should post a request to &lt;a href="http://rubyforge.org/projects/zentest" rel="nofollow"&gt;http://rubyforge.org/projects/zentest&lt;/a&gt; for that.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Jan 2008 15:28:02 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4822f024-8d16-4aaf-b640-2d3ba03b3112</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-421</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Tick</title>
      <description>&lt;p&gt;I&amp;#8217;m using autotest and rspec on WinXP. Now the annoying &amp;#8220;Dunno!&amp;#8221; messages are gone but I had to change the homepath in autotest.rb. The microsoft commandline can&amp;#8217;t handle &amp;#8217;~/.autotest&amp;#8217;. 
&amp;#8217;$home/.autotest&amp;#8221; works better.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Jan 2008 13:49:02 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9a06bd4b-e6eb-4079-82f8-4852c6a7b711</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-420</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Mike Subelsky</title>
      <description>&lt;p&gt;David,&lt;/p&gt;


	&lt;p&gt;This was really helpful to me.  I posted the .autotest files I setup using your example in case anyone needs inspiration or would like to see how add_mapping works:&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.subelsky.com/2008/01/autotest-with-verbose-flag-on.html" rel="nofollow"&gt;http://www.subelsky.com/2008/01/autotest-with-verbose-flag-on.html&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;-Mike&lt;/p&gt;</description>
      <pubDate>Thu, 17 Jan 2008 13:44:47 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5c96564c-9539-49c5-98dd-88bccd1b5586</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-419</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by David Chelimsky</title>
      <description>&lt;p&gt;@Wincent &amp;#8211; Nice screencast. And yes, the modification methods (rather than simple accessors) were just added to 3.8.0.&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jan 2008 13:11:15 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ea26ba72-7fa4-43a0-91f6-1ab3caac327d</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-418</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Wincent Colaiuta</title>
      <description>&lt;p&gt;I published a &lt;a href="http://wincent.com/a/about/wincent/weblog/archives/2008/01/rspec_autotest.php" rel="nofollow"&gt;screencast&lt;/a&gt; about this this morning, but I wasn&amp;#8217;t sure whether add_mapping and friends were new in 3.8.0, or had been in for longer and I just hadn&amp;#8217;t noticed them&amp;#8230; I had tried to override mappings in the past without this and it was fiendishly hacky and difficult.&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jan 2008 10:27:43 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:34f351d3-1734-4633-a816-ee71cbfe4056</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-417</link>
    </item>
    <item>
      <title>"RSpec-1.1.2 and ZenTest-3.8.0" by Scott Nedderman</title>
      <description>&lt;p&gt;Thanks Ryan and David.  This works great.&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jan 2008 02:31:14 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2911cb53-3186-404b-b3c9-24f879752d4d</guid>
      <link>http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0#comment-416</link>
    </item>
  </channel>
</rss>
