<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nick evans - devblog &#187; code</title>
	<atom:link href="http://ekenosen.net/nick/devblog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://ekenosen.net/nick/devblog</link>
	<description>thoughts on software craftsmanship and other technobabble</description>
	<lastBuildDate>Wed, 27 May 2009 18:00:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>a better progress bar for rspec</title>
		<link>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 20:00:26 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=53</guid>
		<description><![CDATA[Updated 2008-12-10: added screenshot and video.
I&#8217;ve always been a little bit bemused by the default ruby test/unit and rspec output: a series of dots, one for each passing test (or example), and the dots become &#8220;F&#8221; characters in the event of a failure.  Most importantly: it&#8217;s simple, unambiguous about pass/fail, and easy to read at [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Updated 2008-12-10:</strong> <em>added screenshot and video.</em></p>
<p>I&#8217;ve always been a little bit bemused by the default ruby test/unit and rspec output: a series of dots, one for each passing test (or example), and the dots become &#8220;F&#8221; characters in the event of a failure.  Most importantly: it&#8217;s simple, unambiguous about pass/fail, and easy to read at a glance, so no problem there.  You get a feel for the speed at which the tests are running, and you can visualize how many tests have run already.  And it&#8217;s easy enough to have them output in color (red or green), to make the errors visually pop out.  And it&#8217;s drop dead simple.  That&#8217;s good.</p>
<h3>So what&#8217;s missing?</h3>
<p><em>(for my tastes)</em></p>
<ul>
<li><strong>Immediate Feedback</strong>:  Yeah, the default output gives me an &#8220;F&#8221;, but what am I supposed to do with an &#8220;F&#8221;?  I won&#8217;t know where and what that &#8220;F&#8221; was until the end of the entire test run, when the summary is dumped.  When running through a (functional) test suite that takes three minutes or even fifteen minutes, that just doesn&#8217;t work.</li>
<li><strong>Concise output</strong>: if everything is passing, I don&#8217;t need to see 4000+ dots displayed across my screen.  It would be nice if the entire output would fit into a single line (when there are no failures).</li>
<li><strong>Percentage</strong>:  A nice to have, not a need to have.  But knowing how many tests have already run is generally not as interesting to me as how many tests are there total, and what percentage of them have run.</li>
<li><strong>ETA</strong>: This isn&#8217;t so important for the short test runs that I do over and over again during the BDD cycle&#8230; because I expect those tests to finish in under 10 seconds anyway.  But anything more than 10 seconds, and I get distracted.  An ETA helps me limit my distraction.</li>
</ul>
<h3>So what do I do about it?</h3>
<p>Basically, what I want is a progress bar and that the errors and warnings be displayed immediately. I also want warnings to be printed for slow specs. When using color, I want the entire progress bar printed in green if everything is good, yellow if there has been a warning, and red if there has been an error.</p>
<p>Fortunately, rspec makes it <em>very</em> simple to write a custom output formatter. So, a couple of weekends ago, I threw something together in about half an hour.  I&#8217;ve used it ever since, and I&#8217;m pretty happy with it (I&#8217;ve tweaked it a little bit).</p>
<h3>What does it look like?</h3>
<p>A static image doesn&#8217;t really show off the progress bar very well, but here&#8217;s a screenshot (click thumbnail for full-size):</p>
<p style="text-align: center;"><a href="http://ekenosen.net/nick/devblog-uploads/2008/12/rspec_progress_bar_example.jpg"><img class="size-medium wp-image-87 aligncenter" title="rspec_progress_bar_example" src="http://ekenosen.net/nick/devblog-uploads/2008/12/rspec_progress_bar_example-300x276.jpg" alt="" width="300" height="276" /></a></p>
<p>And here is a video, so you can see it in action (very low quality, sorry):</p>
<p style="text-align: center;"><embed id="VideoPlayback" src="http://video.google.com/googleplayer.swf?docid=-6454522180447850859&#038;hl=en&#038;fs=true" style="width:400px;height:326px" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"> </embed></p>
<h3>The code</h3>
<p><a href="http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb">http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb</a></p>
<p>It&#8217;s currently hosted in a <a href="http://bazaar-vcs.org/">bzr</a> branch, but I&#8217;ll stick it up on github if anyone really cares about that.  Also, it depends upon the progressbar gem, so you&#8217;ll need to install that.</p>
<h3>To use it</h3>
<p>The location you download the script to is not important, but this is where I&#8217;m (currently) keeping it. You could also use bzr to pull down the entire branch.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ gem install progressbar
&nbsp;
$ mkdir -p ~/lib/rspec/
$ cd ~/lib/rspec
$ wget http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb
&nbsp;
$ spec --require ~/lib/rspec/compact_progress_bar_formatter.rb -c -f Spec::Runner::Formatter::CompactProgressBarFormatter path/to/specs</pre></div></div>

<p>I&#8217;m currently using some bash aliases to keep the spec command line nice and short.  Perhaps there&#8217;s a better way?  In <code>~/.bash_aliases</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">alias  spb='spec        --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'
alias sspb='script/spec --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'</pre></div></div>

<p>For rake tasks, I use a <code>spec/local_spec.opts</code> (<code>spec/spec.opts</code> is checked into version control as a default).</p>
<h3>Nitpicking</h3>
<p>I cheated: I didn&#8217;t develop it BDD-style.  I intend to fix that soon by rewriting it spec-first; certainly before adding any more functionality. <a href="http://rubyhoedown2008.confreaks.com/05-bryan-liles-lightning-talk-tatft-test-all-the-f-in-time.html">TATFT</a> indeed.</p>
<p>I&#8217;d really like to be able to send the threshold (for reporting of slow specs) in on the command line.  It might be easy to do, I haven&#8217;t looked into it&#8230; I&#8217;m currently just editing the file every time I want to change the threshold (e.g. normal specs run with a threshold of 0.1 sec, functional specs run with a threshold of 5 or 10 seconds).  Messy.</p>
<p>Also, it would be nice if the command line didn&#8217;t need to be so long&#8230; perhaps a supported gem/plugin system for rspec?  If that were easily doable, then I would probably package this up into a gem.</p>
<p>I had to break into the progressbar&#8217;s internals a little bit&#8230; it didn&#8217;t publically expose all of the functionality I wanted.  Still, that&#8217;s better than creating my own progressbar library.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
