Nick Sieger: Category testing http://blog.nicksieger.com/articles/category/testing en-us 40 Auto RSpec <p><em>Update: (2 months later) If you&#8217;re reading this, you&#8217;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 &#8220;may work for you.&#8221; It&#8217;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&#8217;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&#8217;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&#8217;re using RSpec on Rails didn&#8217;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&#8217;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&#8217;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 &quot;lib/spec/.*&quot; -Ilib --rails &quot;/usr/lib/ruby/gems/1.8/gems/rspec-0.6.0/bin/spec&quot; -- --diff</span><span class="punct">}</span> <span class="keyword">end</span> <span class="keyword">end</span></code></pre></div> Wed, 13 Sep 2006 20:35:00 +0000 urn:uuid:52bf2e58-ea0e-4473-bad5-c7b42775bfee Nick Sieger http://blog.nicksieger.com/articles/2006/09/13/auto-rspec testing ruby rails ruby autotest rspec testing http://blog.nicksieger.com/articles/trackback/59