Nick Sieger: Tag autotestdo what you lovetag:blog.nicksieger.com,2005:TypoTypo2007-08-31T17:25:45+00:00Nick Siegerurn:uuid:52bf2e58-ea0e-4473-bad5-c7b42775bfee2006-09-13T20:35:00+00:002007-08-31T17:25:45+00:00Auto RSpec<p><em>Update: (2 months later) If you’re reading this, you’re probably interested in <a href="/articles/2006/11/15/rspec-autotest-now-a-rails-plugin">my Rails plugin for this</a> instead.</em></p>
<p>Hot off the presses, after a few hours of hacking and tweaking, may I present Auto+RSpec, otherwise known as The Mashup of <a href="http://rspec.rubyforge.org/tools/rails.html">RSpec on Rails</a> and <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">autotest</a>. This is not an official release of any sort, but “may work for you.” It’s not a clean hack, as it exposes some areas for autotest to grow if the maintainers decide to open it up to alternatives to Test::Unit. After spending a little time looking at the autotest code, I think it would be nice to allow hooks for autotest plugins to define project conventions (i.e., <code>@exceptions</code> and the <code>#tests_for_file</code> method) as well as a result parsing API.</p>
<p>For now, if you’re an RSpec on Rails user, you can try this out as follows:</p>
<ul>
<li>Install <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">ZenTest</a> if you haven’t already: <code>sudo gem install ZenTest</code>.</li>
<li>Download <a href="http://svn.caldersphere.net/svn/main/rspec_autotest/trunk/lib/rspec_autotest.rb">rspec_autotest.rb</a> and put in your <code>vendor/plugins/rspec/lib</code> directory (you did say you’re using RSpec on Rails didn’t you?)</li>
<li>Download <a href="http://svn.caldersphere.net/svn/main/rspec_autotest/trunk/tasks/rspec_autotest.rake">rspec_autotest.rake</a> and put in your <code>lib/tasks</code> directory</li>
<li>Start <code>autotest</code> with rake by typing <code>rake spec:autotest</code></li>
<li>Note: if you’re using RSpec 0.6, you might have better success with <a href="http://svn.caldersphere.net/svn/main/rspec_autotest/tags/rspec-0.6.0">the files located here</a>.</li>
</ul>
<p>Next steps for this will be to work out whether this code should live in RSpec on Rails or autotest, or some combination of those.</p>
<p>Now, spec’ers, be off in search of that <strong>Red/Green/Refactor</strong> rhythm of which sage agilists speak!</p>
<p><strong>Bonus tip</strong>: add the following code to your <code>.autotest</code> file to run <code>spec</code> with <code>rcov</code>:</p>
<div class="typocode"><pre><code class="typocode_ruby "> <span class="constant">Autotest</span><span class="punct">.</span><span class="ident">add_hook</span> <span class="symbol">:initialize</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">at</span><span class="punct">|</span>
<span class="comment"># run spec with rcov</span>
<span class="keyword">if</span> <span class="ident">at</span><span class="punct">.</span><span class="ident">respond_to?</span> <span class="symbol">:spec_command</span>
<span class="ident">at</span><span class="punct">.</span><span class="ident">spec_command</span> <span class="punct">=</span> <span class="punct">%{</span><span class="string">rcov --exclude "lib/spec/.*" -Ilib --rails "/usr/lib/ruby/gems/1.8/gems/rspec-0.6.0/bin/spec" -- --diff</span><span class="punct">}</span>
<span class="keyword">end</span>
<span class="keyword">end</span></code></pre></div>Nick Siegerurn:uuid:ea568e8e-e6f4-4fb7-80df-8da5f50065b92007-01-30T02:16:00+00:002007-08-31T18:00:07+00:00RSpec Autotest for Standalone Projects<p>I know there has been some demand out there for a version of my <a href="/articles/2006/11/15/rspec-autotest-now-a-rails-plugin">RSpec Autotest Rails plugin</a> that works with standalone (non-Rails) projects, so I finally caved and coded it up. I really hope this does finally get accepted as <a href="https://rubyforge.org/tracker/?func=detail&aid=6732&group_id=419&atid=1680">a patch to ZenTest</a> (nudge, nudge), but until it gets a more standard release, do try it out:</p>
<ol>
<li>Ensure you have ZenTest installed (<code>gem install ZenTest</code>).</li>
<li><a href="http://svn.caldersphere.net/svn/main/rspec_autotest/trunk/lib/rspec_autotest.rb">Download the rspec_autotest.rb file here</a> and put it in the <code>spec</code> directory of your project.</li>
<li>Add this snippet of code into your <code>Rakefile</code>, and <code>rake spec:autotest</code> as usual.</li>
</ol>
<div class="typocode"><pre><code class="typocode_ruby "><span class="ident">namespace</span> <span class="symbol">:spec</span> <span class="keyword">do</span>
<span class="ident">task</span> <span class="symbol">:autotest</span> <span class="keyword">do</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">./spec/rspec_autotest</span><span class="punct">'</span>
<span class="constant">RspecAutotest</span><span class="punct">.</span><span class="ident">run</span>
<span class="keyword">end</span>
<span class="keyword">end</span></code></pre></div>
<p>Once again, happy spec’ing, and let me know of any issues you have with it.</p>