<?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>Meta Bates &#187; testing</title>
	<atom:link href="http://www.metabates.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:25:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Testing Tools Aren&#8217;t All the Same, Choose Wisely</title>
		<link>http://www.metabates.com/2011/03/04/407-testing-tools-arent-all-the-same-choose-wisely/</link>
		<comments>http://www.metabates.com/2011/03/04/407-testing-tools-arent-all-the-same-choose-wisely/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 15:57:04 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[steak]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=407</guid>
		<description><![CDATA[&#8220;Testing is painful.&#8221; &#8220;Testing is hard.&#8221; &#8220;Testing is complicated.&#8221; &#8220;Testing is not fun.&#8221; I hear those sorts of things all the time when I talk to people about testing. I agree that sometimes testing can be all of those things, but if you choose the right tools, the tools that best suite you, testing doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><img class="alignright" title="mario" src="http://www.divanikkiz.com/site/images/stories/mlss_mario-hammer.jpg" alt="" width="255" height="282" />&#8220;Testing is painful.&#8221;</p></blockquote>
<blockquote><p>&#8220;Testing is hard.&#8221;</p></blockquote>
<blockquote><p>&#8220;Testing is complicated.&#8221;</p></blockquote>
<blockquote><p>&#8220;Testing is not fun.&#8221;</p></blockquote>
<p>I hear those sorts of things all the time when I talk to people about testing. I agree that sometimes testing can be all of those things, but if you choose the right tools, the tools that best suite you, testing doesn&#8217;t have to be. Let me give you an example of what I&#8217;m talking about, how choosing the right tools can make a huge impact on how you feel about testing.</p>
<p>When working for a client recently I came across the need for end to end integration testing. I needed to test, amongst other things, the flow of a user registering through the application in a few different ways. Because registration behaves differently based on where you come from and where you want to go, I needed a good way to test that entire flow, so simple unit and functional tests just were not going to cut it.</p>
<p>In the Ruby community there is a big push to use a testing framework called, <a href="http://cukes.info/" target="_blank">Cucumber</a>. Cucumber is a behavior driven development (BDD) tool that let&#8217;s you write user stories in plain English. Those stories then get translated into Ruby code that tests those stories against your application. Because of it&#8217;s popularity, and some of it&#8217;s quite amazing features, this was my first stop on the path to integration testing bliss.</p>
<p>Let me give you an example of a Cucumber script:</p>
<div id="gist-854764" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">Feature:</span><span class="nf"> Registration</span></div><div class='line' id='LC2'><span class="nf">  In order to use My Great Application</span></div><div class='line' id='LC3'><span class="nf">  As a user</span></div><div class='line' id='LC4'><span class="nf">  I want to be able to register</span></div><div class='line' id='LC5'><span class="nf">  </span></div><div class='line' id='LC6'><span class="nf">  </span><span class="k">Scenario:</span><span class="nf"> &#39;Standard Registration&#39;</span></div><div class='line' id='LC7'><span class="k">    Given </span><span class="nf">I am not currently logged in</span></div><div class='line' id='LC8'><span class="nf">    </span><span class="k">When </span><span class="nf">I am on the signup page</span></div><div class='line' id='LC9'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should see &quot;</span><span class="s">Sign Up</span><span class="nf">&quot;</span></div><div class='line' id='LC10'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Name (required)</span><span class="nf">&quot; with &quot;</span><span class="s">Mickey Dolenz</span><span class="nf">&quot;</span></div><div class='line' id='LC11'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Email (required)</span><span class="nf">&quot; with &quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot;</span></div><div class='line' id='LC12'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Password (required)</span><span class="nf">&quot; with &quot;</span><span class="s">password</span><span class="nf">&quot;</span></div><div class='line' id='LC13'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Password confirmation</span><span class="nf">&quot; with &quot;</span><span class="s">password</span><span class="nf">&quot;</span></div><div class='line' id='LC14'><span class="nf">    </span><span class="k">And </span><span class="nf">I press &quot;</span><span class="s">Register</span><span class="nf">&quot;</span></div><div class='line' id='LC15'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should see &quot;</span><span class="s">Sign Up - Confirm Your Account</span><span class="nf">&quot;</span></div><div class='line' id='LC16'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should be on the registration thank you page</span></div><div class='line' id='LC17'><span class="nf">    </span><span class="k">Then </span><span class="nf">&quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot; should receive an email</span></div><div class='line' id='LC18'><span class="nf">    </span><span class="k">When </span><span class="nf">I open the email</span></div><div class='line' id='LC19'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should see &quot;</span><span class="s">Confirm my account</span><span class="nf">&quot; in the email body</span></div><div class='line' id='LC20'><span class="nf">    </span><span class="k">When </span><span class="nf">I follow &quot;</span><span class="s">Confirm my account</span><span class="nf">&quot; in the email</span></div><div class='line' id='LC21'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should be on the welcome page</span></div><div class='line' id='LC22'><span class="nf">    </span><span class="k">And </span><span class="nf">I should see &quot;</span><span class="s">Welcome to the Great Application</span><span class="nf">&quot;</span></div><div class='line' id='LC23'><span class="nf">    </span></div><div class='line' id='LC24'><span class="nf">  </span><span class="k">Scenario:</span><span class="nf"> &#39;Accepting an invitation&#39;</span></div><div class='line' id='LC25'><span class="k">    Given </span><span class="nf">I am not currently logged in</span></div><div class='line' id='LC26'><span class="nf">    </span><span class="k">And </span><span class="nf">the &quot;</span><span class="s">Boys and Girls Club</span><span class="nf">&quot; invites &quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot; to join</span></div><div class='line' id='LC27'><span class="nf">    </span><span class="k">Then </span><span class="nf">&quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot; should receive an email</span></div><div class='line' id='LC28'><span class="nf">    </span><span class="k">When </span><span class="nf">I open the email</span></div><div class='line' id='LC29'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should see &quot;</span><span class="s">Accept Invitation</span><span class="nf">&quot; in the email body</span></div><div class='line' id='LC30'><span class="nf">    </span><span class="k">When </span><span class="nf">I follow &quot;</span><span class="s">Accept Invitation</span><span class="nf">&quot; in the email</span></div><div class='line' id='LC31'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should be on the signup page</span></div><div class='line' id='LC32'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should see &quot;</span><span class="s">Sign Up</span><span class="nf">&quot;</span></div><div class='line' id='LC33'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Name (required)</span><span class="nf">&quot; with &quot;</span><span class="s">Mickey Dolenz</span><span class="nf">&quot;</span></div><div class='line' id='LC34'><span class="nf">    </span><span class="k">And </span><span class="nf">the &quot;</span><span class="s">Email (required)</span><span class="nf">&quot; field should contain &quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot;</span></div><div class='line' id='LC35'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Password (required)</span><span class="nf">&quot; with &quot;</span><span class="s">password</span><span class="nf">&quot;</span></div><div class='line' id='LC36'><span class="nf">    </span><span class="k">And </span><span class="nf">I fill in &quot;</span><span class="s">Password confirmation</span><span class="nf">&quot; with &quot;</span><span class="s">password</span><span class="nf">&quot;</span></div><div class='line' id='LC37'><span class="nf">    </span><span class="k">And </span><span class="nf">I press &quot;</span><span class="s">Register</span><span class="nf">&quot;</span></div><div class='line' id='LC38'><span class="nf">    </span><span class="k">Then </span><span class="nf">the account &quot;</span><span class="s">mickey@monkees.com</span><span class="nf">&quot; should be &quot;</span><span class="s">activated</span><span class="nf">&quot;</span></div><div class='line' id='LC39'><span class="nf">    </span><span class="k">Then </span><span class="nf">I should be on the accept/decline invitation page</span></div><div class='line' id='LC40'><span class="nf">    </span><span class="k">And </span><span class="nf">I should see &quot;</span><span class="s">Join the Boys and Girls Club</span><span class="nf">&quot;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/854764/81be0e41bf076636677685e985192e211aa693e0/registration.feature" style="float:right;">view raw</a>
            <a href="https://gist.github.com/854764#file_registration.feature" style="float:right;margin-right:10px;color:#666">registration.feature</a>
            <a href="https://gist.github.com/854764">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>That script tests the user registration flow through an application in a couple of different ways, first through &#8216;standard&#8217; registration, and then through being invited to join. Now, the beauty of Cucumber is that these scripts are &#8216;human&#8217; readable. Your product manager, or other stake holders, should be able to write these scripts themselves, and you, the developer, should be able to just plug them in and code until those scripts pass.</p>
<p>Unfortunately, while that sounds like a little slice of Heaven, the reality is far from it in practice. First, getting stake holders to actually write these &#8216;stories&#8217;, as their typically called, is a tough chore to begin with. If they do write them, they&#8217;re typically not going to be &#8216;plug and play&#8217;. Why? Well, when Cucumber reads these scripts it goes line by line and tries to find some code that matches the regular expression of that line and then execute it. If it doesn&#8217;t find matching code, then it fails. That means that your stake holders need to write these scripts in a very particular way or developers need to sit down and massage those stories to fit the correct regular expression.</p>
<p>Now, let me just take this opportunity to say that this is not a post about how much I hate Cucumber, in fact I think Cucumber is a pretty amazing piece of software, and does in fact have a lot of great uses. Instead, what I&#8217;m talking about it is how Cucumber turned out not to be the right tool for the job for me on a recent project.</p>
<p>So why wasn&#8217;t Cucumber the right tool for the job? Great question, glad you asked. Cucumber turned out not to be the right tool for a few reasons. The biggest of which was that I was the one who was writing the user stories. The stake holders had no desire to write these stories, which meant I had to write them. The I had to write the &#8216;steps&#8217; that back each line of the script. In all fairness, Cucumber does give you some great steps right out of the box. After some fiddling I finally got the Cucumber scripts up and running and testing my work flow. But I definitely ran into some issues.</p>
<p>Because Cucumber isn&#8217;t pure Ruby I had a hard time doing something as simple as just printing out the request&#8217;s body and headers without having to write a step that did just that, then add that step to my story, etc&#8230; It&#8217;s overall fiddlyness and non-intuitive way of doing things caused me a lot of grief and time. And, most importantly, I wasn&#8217;t really getting the big benefit of Cucumber, stake holder&#8217;s writing the stories. So I was doing all this work and not getting the benefits of Cucumber.</p>
<p>So what did I do? I turned to a library called <a href="https://github.com/cavalle/steak" target="_blank">Steak</a>. Steak allows you to write integration tests using pure Ruby and integrates directly in with <a href="http://relishapp.com/rspec" target="_blank">RSpec</a>, my preferred testing framework. With Steak I was able to write my integration tests in just a few minutes.</p>
<div id="gist-854844" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nb">require</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;/acceptance_helper&#39;</span><span class="p">)</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="n">feature</span> <span class="s2">&quot;Registration Steak&quot;</span><span class="p">,</span> <span class="sx">%q{</span></div><div class='line' id='LC4'><span class="sx">  In order to use My Great Application</span></div><div class='line' id='LC5'><span class="sx">  As a user</span></div><div class='line' id='LC6'><span class="sx">  I want to be able to register</span></div><div class='line' id='LC7'><span class="sx">}</span> <span class="k">do</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="n">scenario</span> <span class="s2">&quot;register throught the standard registration process&quot;</span> <span class="k">do</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">visit</span> <span class="n">signup_path</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">expect</span> <span class="p">{</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fill_in_registration</span><span class="p">(</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;Mickey Dolenz&#39;</span><span class="p">,</span> <span class="ss">:email</span> <span class="o">=&gt;</span> <span class="s1">&#39;mickey@monkees.com&#39;</span><span class="p">)</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span><span class="o">.</span><span class="n">to</span> <span class="n">change</span><span class="p">(</span><span class="n">delivered_emails</span><span class="p">,</span> <span class="ss">:size</span><span class="p">)</span><span class="o">.</span><span class="n">by</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">find_by_email</span><span class="p">(</span><span class="s1">&#39;mickey@monkees.com&#39;</span><span class="p">)</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span><span class="o">.</span><span class="n">should</span> <span class="n">be_unverified</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">page</span><span class="o">.</span><span class="n">should</span> <span class="n">have_content</span><span class="p">(</span><span class="s1">&#39;You have signed up successfully. However, we could not sign you in because your account is unconfirmed.&#39;</span><span class="p">)</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">root_path</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">visit</span> <span class="n">signin_path</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fill_in</span> <span class="s1">&#39;user_email&#39;</span><span class="p">,</span> <span class="ss">:with</span> <span class="o">=&gt;</span> <span class="s1">&#39;mickey@monkees.com&#39;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fill_in</span> <span class="s1">&#39;user_password&#39;</span><span class="p">,</span> <span class="ss">:with</span> <span class="o">=&gt;</span> <span class="s1">&#39;password&#39;</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">click_button</span> <span class="s1">&#39;Sign In&#39;</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">page</span><span class="o">.</span><span class="n">should</span> <span class="n">have_content</span><span class="p">(</span><span class="s1">&#39;You have to confirm your account before continuing.&#39;</span><span class="p">)</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">new_user_session_path</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">click_email_link_matching</span><span class="p">(</span><span class="sr">/users\/confirmation/</span><span class="p">,</span> <span class="n">delivered_emails</span><span class="o">.</span><span class="n">first</span><span class="p">)</span></div><div class='line' id='LC31'><br/></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">welcome_users_path</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">page</span><span class="o">.</span><span class="n">should</span> <span class="n">have_content</span><span class="p">(</span><span class="s1">&#39;Welcome to the Great Application&#39;</span><span class="p">)</span></div><div class='line' id='LC34'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span><span class="o">.</span><span class="n">reload</span></div><div class='line' id='LC35'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span><span class="o">.</span><span class="n">should</span> <span class="n">be_activated</span></div><div class='line' id='LC36'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC37'>&nbsp;&nbsp;</div><div class='line' id='LC38'>&nbsp;&nbsp;<span class="n">scenario</span> <span class="s2">&quot;register from an invitation&quot;</span> <span class="k">do</span></div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">mark</span> <span class="o">=</span> <span class="n">users</span><span class="p">(</span><span class="ss">:mark</span><span class="p">)</span></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">organization</span> <span class="o">=</span> <span class="n">mark</span><span class="o">.</span><span class="n">organizations</span><span class="o">.</span><span class="n">first</span></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">signin</span><span class="p">(</span><span class="n">mark</span><span class="p">)</span></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">visit</span> <span class="n">new_organization_invitation_path</span><span class="p">(</span><span class="n">organization</span><span class="p">)</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">expect</span> <span class="p">{</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">expect</span> <span class="p">{</span></div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fill_in</span> <span class="s1">&#39;organization_invitation_worker_emails&#39;</span><span class="p">,</span> <span class="ss">:with</span> <span class="o">=&gt;</span> <span class="s1">&#39;mickey@monkees.com&#39;</span></div><div class='line' id='LC47'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">click_button</span> <span class="s1">&#39;Send Invites&#39;</span></div><div class='line' id='LC48'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">DJ</span><span class="o">.</span><span class="n">first</span><span class="o">.</span><span class="n">invoke_job</span></div><div class='line' id='LC49'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span><span class="o">.</span><span class="n">to</span> <span class="n">change</span><span class="p">(</span><span class="n">delivered_emails</span><span class="p">,</span> <span class="ss">:size</span><span class="p">)</span><span class="o">.</span><span class="n">by</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div><div class='line' id='LC50'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span><span class="o">.</span><span class="n">to</span> <span class="n">change</span><span class="p">(</span><span class="n">organization</span><span class="o">.</span><span class="n">invitations</span><span class="p">,</span> <span class="ss">:count</span><span class="p">)</span><span class="o">.</span><span class="n">by</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div><div class='line' id='LC51'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC52'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">invitation</span> <span class="o">=</span> <span class="n">organization</span><span class="o">.</span><span class="n">invitations</span><span class="o">.</span><span class="n">first</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC54'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">signout</span></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">click_first_link_in_email</span><span class="p">(</span><span class="n">delivered_emails</span><span class="o">.</span><span class="n">first</span><span class="p">)</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">signup_path</span></div><div class='line' id='LC59'><br/></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fill_in_registration</span><span class="p">(</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;Mickey Dolenz&#39;</span><span class="p">)</span></div><div class='line' id='LC61'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC62'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">organization_invitation_path</span><span class="p">(</span><span class="n">organization</span><span class="p">,</span> <span class="n">invitation</span><span class="p">)</span></div><div class='line' id='LC63'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC64'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">find_by_email</span><span class="p">(</span><span class="s1">&#39;mickey@monkees.com&#39;</span><span class="p">)</span></div><div class='line' id='LC65'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">user</span><span class="o">.</span><span class="n">should</span> <span class="n">be_activated</span></div><div class='line' id='LC66'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC67'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">expect</span> <span class="p">{</span></div><div class='line' id='LC68'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">click_on</span> <span class="s1">&#39;Get Started Now!&#39;</span></div><div class='line' id='LC69'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span><span class="o">.</span><span class="n">to</span> <span class="n">change</span><span class="p">(</span><span class="n">user</span><span class="o">.</span><span class="n">organizations</span><span class="p">,</span> <span class="ss">:count</span><span class="p">)</span><span class="o">.</span><span class="n">by</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div><div class='line' id='LC70'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC71'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">current_path</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="n">organization_campaign_path</span><span class="p">(</span><span class="n">organization</span><span class="p">,</span> <span class="n">organization</span><span class="o">.</span><span class="n">campaigns</span><span class="o">.</span><span class="n">first</span><span class="p">)</span></div><div class='line' id='LC72'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC73'>&nbsp;&nbsp;</div><div class='line' id='LC74'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/854844/45d1d080b1d1a19954d6894e08e2261b1b368166/registration_spec.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/854844#file_registration_spec.rb" style="float:right;margin-right:10px;color:#666">registration_spec.rb</a>
            <a href="https://gist.github.com/854844">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>While my Steak scripts a bit more wordy and are definitely not &#8216;human&#8217; readable and editable by stakeholders, they did achieve my goal of allowing me to write integration tests quickly.</p>
<p>So here you see I picked a very powerful tool, that has a lot of great benefits, Cucumber, but I picked it for the wrong reasons. I picked it because it was popular, and not because it would help me achieve my goals. If my goals where to have stakeholders write the stories and hand them off to development, than it would&#8217;ve been a better choice. But in the end my goal was to write integration tests and write them quickly, which is why Steak ended up being the right tool for that job.</p>
<p>This has all been a really long winded way of saying doing some research before choosing your testing frameworks, or any framework for that matter. Play with it, research it, make sure it meets your goals, not somebody else&#8217;s. If you choose the right tools then testing doesn&#8217;t need to be scary, complicated, frustrating, etc&#8230; Testing is a <a href="http://www.metabates.com/2010/07/01/testing-is-not-an-option/">requirement</a> and a must have, so why not make it fun?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2011/03/04/407-testing-tools-arent-all-the-same-choose-wisely/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Become a Test-driven Developer</title>
		<link>http://www.metabates.com/2010/10/12/how-to-become-a-test-driven-developer/</link>
		<comments>http://www.metabates.com/2010/10/12/how-to-become-a-test-driven-developer/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 16:31:01 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=367</guid>
		<description><![CDATA[In a previous post, Testing Is Not An Option, I talked a lot about why you should write tests, and the arguments you can put forth to your client, manager, or whoever it may be as to why you should write tests. What I didn&#8217;t talk about was how to start writing tests. So let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, <a href="http://www.metabates.com/2010/07/01/testing-is-not-an-option/" target="_blank">Testing Is Not An Option</a>, I talked a lot about why you should write tests, and the arguments you can put forth to your client, manager, or whoever it may be as to why you should write tests. What I didn&#8217;t talk about was how to start writing tests. So let&#8217;s talk about that for a bit, shall we?</p>
<p>When I&#8217;m talking with a potential client, well at least a client that has an existing code base, I always ask what their code coverage stats are. Now, I know at code coverage stats aren&#8217;t the be all end all of measuring how good your tests are, but they&#8217;re a basic enough metric to use as a guide. If they say they&#8217;re high, then I usually dig in more about how they&#8217;re testing; what frameworks, BDD, TDD, that sort of thing. Usually though I get a few minutes where they apologize and sheepishly give me their reasons for having little or no tests.</p>
<p>Here are few of those reasons:</p>
<ul>
<li>We don&#8217;t/didn&#8217;t have the time.</li>
<li>We don&#8217;t know how.</li>
<li>It was/is too complicated.</li>
<li>It was/is too overwhelming.</li>
</ul>
<p>Let&#8217;s talk about each of this points for a minute.</p>
<h3>&#8220;We don&#8217;t/didn&#8217;t have the time.&#8221;</h3>
<h3><span style="font-weight: normal; font-size: 13px;">I never accept time as an argument against testing. Testing ends up repaying it&#8217;s time investment, and will ultimately give you more time than if you didn&#8217;t write code. It&#8217;s a win-win. Again see my previous post in how to get the time signed off on as part of t he project timeline.</span></h3>
<h3>&#8220;We don&#8217;t know how.&#8221;</h3>
<p>Learn. There&#8217;s no better time than the present and no better way to learn than being thrown into the deep end. The web is crawling with documentation, screen casts, how to articles and tutorials, and there are plenty of books to get you going. In short the k knowledge is literally at your finger tips, and to be honest it&#8217;s easier than you think.</p>
<h3>&#8220;It was/is too complicated.&#8221;</h3>
<p>That usually means you&#8217;re doing it wrong. Take a step back and assess what it is you&#8217;re trying to do. You&#8217;re tests should be simple and concise. Don&#8217;t write tests that are hundreds of lines long. They&#8217;re tests, not entrance exams to MIT.</p>
<h3>&#8220;It was/is too overwhelming.&#8221;</h3>
<p>Certainly if you didn&#8217;t write tests as you went along it can get quite overwhelming thinking about all the tests you now need to write for your monolithic app. I&#8217;ll talk about how you can solve that problem in a minute.</p>
<h2>Making It Happen</h2>
<p>Ok, so now that we&#8217;ve identified a few of the excuses let&#8217;s talk about how you can starting writing tests today for your application. So, take a deep breath and let&#8217;s begin.</p>
<p>If you&#8217;re staring at an existing application, don&#8217;t try to tackle it all at once, you&#8217;ll just get overwhelmed, scared, and confused. Instead take it one file/class at a time. First start with your models, as this is where the majority of your application business logic should be. Alphabetically each day pick the next class (or a couple of them) in the list and start to fill our your test files.</p>
<p>What do I mean by fill out your tests files, I mean creating pending tests for each of the methods of your model. Here&#8217;s an example of a basic Ruby* class and what the pending RSpec spec file would look like:</p>
<pre><code># Class: class Entity def tax_id if self.person? # code here else # code here end end def person? # code here end end # Spec: describe Entity do describe "tax_id" do it "should return a Social Security number if the entity is a Person" do pending end it "should return a Tax ID number if the entity is a Corporation" do pending end end describe "person?" do it "should return true if the entity is a person" do pending end it "should return false if the entity is not a person" do pending end end end</code></pre>
<p>Notice how the method that has the if/else statement in it has two pending tests for it. We need to test each variation of the method.</p>
<p>Now when you run your tests you&#8217;ll see that you have a bunch of pending tests. Great! Now you just need to fill them in, but at least you know what should be filled in.</p>
<p>I also recommend that you do this every time you create a new method. As soon as you give your method a name go to your corresponding test and create a pending test for that method. This way you know that you have to test that method later. (In a perfect world I would love to see you write your test before returning to your class to fill in the method itself, but baby steps for now.)</p>
<p>Once you have all your pending tests setup each day try to fill in the details of each pending test for a whole class. If that&#8217;s too much, then try to set aside an hour a day and fill in as many pending tests as you can. Alternatively you can also fill in the tests during the course of the day as you use one of the methods without tests.</p>
<p>Another great way to start filling in your test suite is each time you get a new bug, write a test to reproduce it. This is a great habit to get into as you&#8217;ll eventually have a great suite of regression tests in place to help prevent those nasty bugs from returning. Write the test, see that it fails, then fix your bug. When your teat passes then you know you&#8217;ve fixed the bug!</p>
<p>Finally, start small. Start by writing unit tests. These are the types of tests I just described. They test a very particular part of your code base to ensure that it does what it should do. These tests are typically easy to write and act as a great corner stone to your test suite as a whole. Don&#8217;t try to jump right in with full integration tests. The frameworks typically have a steep learning curve, and are more complicated to get up and running. This will lead to frustration and the old feeling of being overwhelmed. You can add these tests in later as you gain experience.</p>
<p>Well, there you have it, a few simple tricks to help you get started testing today. I know this post was a bit on the lengthy side, but I&#8217;m glad you stuck with me. Your life will be better for it. When you have a large and expansive test suite life is just better. Food tastes better. The sky is bluer. There will be a skip in your step. And you can use your incredibly high code coverage stats as a pick up line in a bar. On second thought, scratch that last thought. I wrote a test to see if that would work and it failed. It failed miserably.</p>
<h6>* Please not that while I use Ruby as the example language here, the concept applies to whatever language you use.</h6>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/10/12/how-to-become-a-test-driven-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CoverMe – Code Coverage for Ruby 1.9 Reaches RC1</title>
		<link>http://www.metabates.com/2010/09/30/coverme-%e2%80%93-code-coverage-for-ruby-1-9-reaches-rc1/</link>
		<comments>http://www.metabates.com/2010/09/30/coverme-%e2%80%93-code-coverage-for-ruby-1-9-reaches-rc1/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 16:09:25 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[cover_me]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=363</guid>
		<description><![CDATA[In August I announced CoverMe a code coverage tool for Ruby 1.9. Well, today I announce that it has hit it&#8217;s first release candidate! I&#8217;ve very excited by the fact it&#8217;s getting close to an &#8216;official&#8217; release. The response to CoverMe has been great and through feedback from the community I&#8217;ve made a lot of [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/">August</a> I announced <a href="http://github.com/markbates/cover_me" target="_blank">CoverMe</a> a code coverage tool for Ruby 1.9. Well, today I announce that it has hit it&#8217;s first release candidate! I&#8217;ve very excited by the fact it&#8217;s getting close to an &#8216;official&#8217; release.</p>
<p>The response to CoverMe has been great and through feedback from the community I&#8217;ve made a lot of improvements and fixed a lot of issues.</p>
<p>While quite a few things have changed under the hood, not much has changed in how you use CoverMe.</p>
<h2>Installation</h2>
<p>The following are instructions for how you would configure CoverMe for a Rails 3 project, adjust to your local environment accordingly.</p>
<p>In  your Gemfile add the following:</p>
<pre>gem 'cover_me', '&gt;= 1.0.0.rc1', :group =&gt; :test</pre>
<p>Then run:</p>
<pre>$ bundle install</pre>
<p>After CoverMe is installed place the following line at the <strong><em>VERY TOP</em></strong> of your &#8216;test_helper.rb&#8217; or &#8216;spec_helper.rb&#8217; file (for Cucumber put it at the top of the &#8216;env.rb&#8217; file):</p>
<pre>require 'cover_me'</pre>
<p>I can&#8217;t emphasize enough how important it is that the require statement is at the <strong><em>VERY</em></strong> top of that file!</p>
<p>Finally (and optionally) run:</p>
<pre>$ rails g cover_me:install</pre>
<p>This will simply install a Rake task that will wrap both Test::Unit and RSpec tasks with CoverMe and will launch the results at the end of the test suites. I would recommend it. It&#8217;s kinda the whole point. <img src='http://www.metabates.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>That&#8217;s it!</h2>
<p>Enjoy the release candidate, and of course, please let me know if you find any issues with it. Issues can be reported on <a href="http://github.com/markbates/cover_me/issues" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/09/30/coverme-%e2%80%93-code-coverage-for-ruby-1-9-reaches-rc1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixtures v. Factories &#8211; Can&#8217;t We All Just Get Along?</title>
		<link>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/</link>
		<comments>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 12:49:37 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[factories]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=358</guid>
		<description><![CDATA[Testing in Ruby on Rails is incredibly easy. I mean stupidly easily. So easy that if you&#8217;re not doing it, you are a very, very bad developer and should re-evaluate your career choices. (Yes, I believe in testing that much!) One thing that is not all that easy, however, is object creation and populating your [...]]]></description>
			<content:encoded><![CDATA[<p>Testing in Ruby on Rails is incredibly easy. I mean stupidly easily. So easy that if you&#8217;re not doing it, you are a very, very bad developer and should re-evaluate your career choices. (Yes, I believe in testing that much!) One thing that is not all that easy, however, is object creation and populating your test database. Five years ago when I first started working with Rails the only options we had to get data into the database were fixtures, or hastily written &#8216;factory&#8217;-esque methods custom to each application.</p>
<p>Fixtures, for those who don&#8217;t know, are YAML files that contain YAML-ized versions of objects that then get loaded into the test database when you run your test suite. These objects can then be pulled back from the database during your tests. Sounds great, doesn&#8217;t it? Well, not everybody thinks so. One of the biggest problems with fixtures is they can very quickly get out of control. Keeping track of all the different scenarios your tests needs can get very confusing and frustrating to deal with.</p>
<p><img class="alignleft" title="Factory Workers" src="http://www.uni.edu/schneidj/webquests/adayinthelife/lotsofworkers.jpg" alt="" width="360" height="283" />So how do we fix this problem? Well, most developers have turned to using factories. Factories allow us to quickly build the data we need for each test, now the building of the data you need for your test is right there in a setup or before method. Easy to manage and keep track of. Now there are a plethora of different factory libraries meant to make this task nicer, a few of the popular ones are <a href="http://github.com/thoughtbot/factory_girl" target="_blank">Factory Girl</a>, <a href="http://github.com/notahat/machinist">Machinist</a>, and <a href="http://github.com/flogic/object_daddy" target="_blank">Object Daddy</a>. The problem with this approach, however, is that it can slow down your tests as you are building database objects for nearly every test, and as we all know, object creation and database inserting can be expensive.</p>
<p>So, what can we do to help solve both of these problems? Well, we can use both of these technologies. Together. Yeah, that&#8217;s right I&#8217;m saying you should use fixtures as well as factories. Sound crazy? Not really. Let me explain.</p>
<p>Most Rails applications have most, if not all, of their functionality behind a login. So whenever we&#8217;re testing some controller action that sites behind a login we need a user to login with. If we were using factories we would have a setup or before method that would create a new User object and save it to the database, and it would do that for every variant of the test, as well as every other test in our suite that needs a user object.</p>
<p>Why not, create one user object and use that repeatedly through our tests? What I like to do is stick one or two users in my fixtures, so that they&#8217;re there whenever I need one. I like to do this with most of my major models. Then, when I need to have some custom scenarios, I can break out the factories and build those custom scenarios.</p>
<p>So what does this achieve? Well, I&#8217;ve sped up my tests by already having a few objects in the database, and not having to create them (and roll them back) with each single test. I&#8217;ve also cleaned up my tests significantly by eliminating a lot of setup and/or before methods where these objects were being created. I&#8217;ve also eliminated the biggest problems with fixtures, that they can get overwhelming, because we are only keeping one or two objects in them and using factories for the rest.</p>
<p>I hoped this helped you to understand that we don&#8217;t have to throw the baby out with the bath water when it comes to fixtures and factories, we can use both. Not go forth and test! Test like your life depends on it (because it does!!).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CoverMe &#8211; Code Coverage for Ruby 1.9</title>
		<link>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/</link>
		<comments>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 17:49:44 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=343</guid>
		<description><![CDATA[Ruby 1.9(.2) is an amazing language to develop applications in. It&#8217;s faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language. When making a move of this size it&#8217;s important to have the right tools to help [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby 1.9(.2) is an amazing language to develop applications in. It&#8217;s faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language.</p>
<div id="_mcePaste">When making a move of this size it&#8217;s important to have the right tools to help us along. Unfortunately, one of the most useful tools as a Ruby developer, <a href="http://github.com/relevance/rcov">RCov</a>, does not work with Ruby 1.9.</div>
<div id="_mcePaste">RCov, for those unfamiliar analyzes your code and tells you which part of your code was not executed. This is INCREDIBLY useful when hooked up to your test suite. While, it&#8217;s not the only metric you should use when determining how good your test coverage it, it certainly is a great first step to point out exactly which parts of your code haven&#8217;t been touched at all!</div>
<p>Enter <a href="http://github.com/markbates/cover_me">CoverMe</a>.</p>
<h2>History</h2>
<p>While working on a Ruby 1.9/Rails 3 project, and loving everything about it (except for the lack of RCov), I came across a <a href="http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/">post</a> by Aaron Patterson (of <a href="http://github.com/tenderlove/nokogiri">Nokogiri</a> fame). In this post he quickly outlined a very basic coverage tool using the new built-in Coverage module in Ruby 1.9.</p>
<p>After spending a morning playing with it, I was quickly able to grow the idea into something useful for the project. Later that day the company I was consulting for (<a href="http://www.biddingforgood.com">BiddingForGood.com</a>), and in particular their chief architect, <a href="http://twitter.com/stuartmg">Stuart Garner</a>, told me to take a day or two and clean it up and release it for the world to use, and so <a href="http://github.com/markbates/cover_me">here</a> it is.</p>
<h2>Features</h2>
<p>Here is a brief overview of the features of CoverMe:</p>
<h3>Index Page</h3>
<ul>
<li>Sortable column headers (File, Lines, Lines of Code, Tested %).</li>
<li>Searching/filtering by file name.</li>
<li>Filtering by coverage percent.</li>
<li>Color coded list of files to quickly see which ones are 100% covered, &gt; 90% covered, or less than 90% covered.</li>
<li>Large color coded average coverage percent, for quick reference.</li>
</ul>
<h3>Detail Page</h3>
<ul>
<li>Line by line coverage report</li>
<li>Color coded lines to quickly see which lines where executed and which ones were not.</li>
<li>Side by side viewing with the corresponding test/spec file (if one exists).</li>
</ul>
<p>See the <a href="http://github.com/markbates/cover_me">README</a> file for more information on installation and usage.</p>
<h2>Thanks</h2>
<p>I would just quickly like to give another quick thanks to Aaron Patterson for pointing out the Coverage module in Ruby 1.9 and inspiring this, hopefully, helpful little gem. Also another big thanks to Stuart Garner for pushing me to package this up and release it to the world.</p>
<h2>Screenshots</h2>

<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/detail_side_by_side/' title='detail_side_by_side'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/detail_side_by_side-150x150.png" class="attachment-thumbnail" alt="detail_side_by_side" title="detail_side_by_side" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/detail/' title='detail'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/detail-150x150.png" class="attachment-thumbnail" alt="detail" title="detail" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index_filter/' title='index_filter'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index_filter-150x150.png" class="attachment-thumbnail" alt="index_filter" title="index_filter" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index_search/' title='index_search'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index_search-150x150.png" class="attachment-thumbnail" alt="index_search" title="index_search" /></a>
<a href='http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/index/' title='index'><img width="150" height="150" src="http://www.metabates.com/wp-content/uploads/2010/08/index-150x150.png" class="attachment-thumbnail" alt="index" title="index" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/08/13/coverme-code-coverage-for-ruby-1-9/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Testing is NOT an Option</title>
		<link>http://www.metabates.com/2010/07/01/testing-is-not-an-option/</link>
		<comments>http://www.metabates.com/2010/07/01/testing-is-not-an-option/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 14:04:38 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.metabates.com/?p=337</guid>
		<description><![CDATA[Five years ago I left the world of contracting and reentered the world of the full time employee, and I enjoyed every minute of it (well, almost). Now fast forward five years and I find myself once again at a crossroads. Do I continue on as an FTE or do I become a contractor, and [...]]]></description>
			<content:encoded><![CDATA[<p>Five years ago I left the world of contracting and reentered the world of the full time employee, and I enjoyed every minute of it (well, almost). Now fast forward five years and I find myself once again at a crossroads. Do I continue on as an FTE or do I become a contractor, and play the field, so to speak? Looks like I&#8217;m going to go with the hired gun route for a little while, but that&#8217;s not really the point of this post.</p>
<p>During the past week or so I&#8217;ve spoken with many great companies and people. I&#8217;ve been fortunate enough to have a high degree of interest in what I can bring to the table. During those discussions I talked with a really nice guy at a what seems to be a really cool company, I won&#8217;t name names, because this isn&#8217;t about either the person or the company, but rather something the engineer said during our phone conversation that got me to thinking.</p>
<p><img class="alignleft" title="Failure Testing" src="http://www.commercialventvac.com/finao/failure_testing.jpg" alt="" width="400" height="240" />&#8220;We don&#8217;t have any tests because I couldn&#8217;t convince the company to allocate the time for them.&#8221; That statement really hung with me. After I got off the phone I started thinking really hard about that statement, and all I could think of was how testing is not an option and people shouldn&#8217;t need to be convinced to have time allocated to them.</p>
<p>As developers it is our responsibility to insist on testing. Always include testing in your time estimates. Never give the client (or your company) an option that includes a time estimate without testing. If a feature takes 2 days to code and a day to write tests, then your estimate is 3 days, never 2. You should never say, &#8220;Well, I can get it done in two days if I don&#8217;t write any tests.&#8221; That&#8217;s just an unacceptable thing to say. What you should be saying is, &#8220;That feature will take three days to code&#8221;.</p>
<p>I don&#8217;t feel I should sit here and tell you all the reasons why you should test, you should know them already, and frankly, they&#8217;re all very obvious! But, if you need a few bullet points to &#8216;convince&#8217; your client, here are a few:</p>
<ul>
<li>Less bugs &#8211; The more tests you have the less bugs you will have. It&#8217;s just a fact. You won&#8217;t have 100% bug free code, that&#8217;s a nearly impossible goal, but you highly reduce the likely hood that as soon as you get your code into production your users will find all the breaking points of your code.</li>
<li>Better maintainability, means faster feature turn around &#8211; When you have a large test suite it means adding, updating, or even removing features because a whole lot easier, which means it SAVES time! Why? Simple, you don&#8217;t have to go through and manually test every aspect of your code to make sure you didn&#8217;t break something elsewhere by adding that validation, or by refactoring that bit of code, etc&#8230; That translates into real $ savings.</li>
<li>Test driven development saves time &#8211; this isn&#8217;t quite the same as my last bullet point. Imagine, if you will, you are writing a four step wizard in your application. If you write a few test scripts using something like Cucumber first before you write your code you can simply keep re-running those to make sure your code is working. If you don&#8217;t have those test scripts written then you continually have to keep going to a browser and entering all the information in each of the steps so you can test something in step four. Which one do you think takes longer, having a few test scripts you can run, or manually going through the four page wizard each time you make a change?</li>
<li>It&#8217;s an investment &#8211; thinking of having test scripts like owning a house. When you don&#8217;t have tests and you just keep testing in the browser or the command line what you are doing is a kin to &#8220;renting&#8221;. There is money being spent, but at the end of the day you have nothing to show for it. You&#8217;ve spent hours &#8220;testing&#8221;, but tomorrow when you come in you have to do it all over again. When you spend those hours writing tests you are actually &#8220;buying&#8221; something. You have something to show for that time and money you&#8217;ve spent. Tomorrow, next week, next month, next year, those scripts will still be there, they&#8217;ll still be working for you, giving  you a return on your investment.</li>
</ul>
<p>Well, I hope I have hopefully made a case to you the engineer as to why you should insist on testing. It&#8217;s the right thing to do, for you, for your application and for you client. If if anyone tries to give you grief about it, send them my way, I&#8217;ll sort em out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2010/07/01/testing-is-not-an-option/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Migration support almost there.</title>
		<link>http://www.metabates.com/2008/04/10/migration-support-almost-there/</link>
		<comments>http://www.metabates.com/2008/04/10/migration-support-almost-there/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 02:49:49 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[data mapper]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=57</guid>
		<description><![CDATA[Now that I&#8217;m back on track with DataMapper, I&#8217;ve got migration support for both it and ActiveRecord just about done. In addition to the actual rake task, db:migrate (btw), I had to set up a good way to test rake tasks, something I&#8217;ll share at a later date, but needless to say it&#8217;s included with [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;m back on track with DataMapper, I&#8217;ve got migration support for both it and ActiveRecord just about done. In addition to the actual rake task, db:migrate (btw), I had to set up a good way to test rake tasks, something I&#8217;ll share at a later date, but needless to say it&#8217;s included with Mack. I also had to deal with the pain in the ass-ness of dealing with two VERY different ORMs, in the same test system! Let me tell you, that sucked!</p>
<p>Good news is that things seem to be working, at least going in the &#8216;up&#8217; direction anyway. I still need to write the &#8216;down&#8217; direction revert stuff. Hopefully, that shouldn&#8217;t take too long now that I have a good way of testing the task and the migration stuff.</p>
<p>Unfortunately, I feel as though as soon as I release this stuff, which should be by the end of this weekend, DataMapper 0.9.0 will be out, and I&#8217;ll have to re-write most of the DataMapper stuff because the API is changing so radically. I guess I&#8217;ll just have to deal with that when the time comes.</p>
<p>In the meantime I&#8217;ll let y&#8217;all know when migrations are done and out there in the wild.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/04/10/migration-support-almost-there/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My thoughts on spec tests</title>
		<link>http://www.metabates.com/2008/04/09/my-thoughts-on-spec-tests/</link>
		<comments>http://www.metabates.com/2008/04/09/my-thoughts-on-spec-tests/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 12:34:54 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[spec test]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=52</guid>
		<description><![CDATA[I&#8217;ve been asked by people why I&#8217;m not using spec tests to test Mack. I&#8217;m currently using just plain old regular unit tests for my tests. It&#8217;s a good question, but not really a valid one, I think. Should it matter what type of tests I&#8217;m using as long as I&#8217;m testing? Tests are tests. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked by people why I&#8217;m not using spec tests to test Mack. I&#8217;m currently using just plain old regular unit tests for my tests. It&#8217;s a good question, but not really a valid one, I think. Should it matter what type of tests I&#8217;m using as long as I&#8217;m testing? Tests are tests. The framework you use to do your tests is moot as long as the tests you write are good, solid tests.</p>
<p>I jumped on the spec test bandwagon about a year or so ago. I forced my whole team to start writing in nothing but spec tests. The team, is still not impressed. If I were to tell them we weren&#8217;t using spec tests anymore, they would be EXTREMELY happy with that.Spec tests are certainly prettier than &#8216;regular&#8217; tests. I&#8217;ll give you that. They are more &#8216;human readable&#8217;. With that said I find assert_equal to be fairly easy to read.</p>
<p>So why do I use regular tests, and not spec tests? A couple of reasons. First, they&#8217;re there and built right in to Ruby, ready to go, no new gems or syntax to learn. They&#8217;re fast. They are faster than spec tests. I see it everyday at work. I can also, and this one is HUGE, run just a single test or a regex&#8217;d series of tests. I really love that last bit. I have yet to find a way to do that, easily, with spec tests.</p>
<p>Again, how people write tests doesn&#8217;t really matter so much to me, it&#8217;s just that they write them. Testing is too easy in Ruby, there&#8217;s just no reason for not writing them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/04/09/my-thoughts-on-spec-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release 0.4.1</title>
		<link>http://www.metabates.com/2008/03/27/release-041/</link>
		<comments>http://www.metabates.com/2008/03/27/release-041/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 21:42:40 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[assigns]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/2008/03/27/release-041/</guid>
		<description><![CDATA[On the heels of yesterdays release of 0.4.0, there is a new release today, 0.4.1. Although this is not a sexy release, as 0.4.0 was, this is an important release. What makes this release so important is that it fixes, adds, or improves testing support for Mack applications. The implementation of some of the testing [...]]]></description>
			<content:encoded><![CDATA[<p>On the heels of yesterdays release of 0.4.0, there is a new release today, 0.4.1. Although this is not a <em>sexy</em> release, as 0.4.0 was, this is an important release.</p>
<p>What makes this release so important is that it fixes, adds, or improves testing support for Mack applications.</p>
<p>The implementation of some of the testing stuff has changed under the covers, but it&#8217;s the new stuff that is really important. let&#8217;s take a look at some of the stuff:</p>
<ul>
<li><strong>assigns(key)</strong> &#8211; This one should be familiar to all you Rails folks out there. This allows you to get an instance variable that was set in a controller, and access it in your test.
<pre>def test_something
  get foo_index_url
  assert_not_nil assigns(:foo_list)
end</pre>
</li>
<li><strong>in_session</strong> &#8211; This methods allows you to wrap a block in the context of a session. This is great if you&#8217;re trying to do integration testing.</li>
<li><strong>set_cookie, remove_cookie</strong> &#8211; These methods allow you to either set or a remove a cookie in your tests. Great if you want to test an action that reads a cookie, or test to see what happens if you set a cookie, then remove the cookie and call something else. Also great to use with the in_session method.</li>
</ul>
<p>There are a few other hidden treats in there, but those are some of the highlights. These things help bring Mack testing to a usable level.</p>
<p>The Mack Demo Blog application has been updated to demonstrate some these things. You can pull the demo using Git here: <a href="git://github.com/markbates/mack_blog_demo.git" target="_blank">git://github.com/markbates/mack_blog_demo.git</a></p>
<p>Changelog:</p>
<ul>
<li>Improved testing support.</li>
</ul>
<ul>
<li>Added assigns support to testing. This is allows for pulling instance variables that were set in a controller to tests.</li>
</ul>
<ul>
<li>Added ability to do &#8216;session&#8217; based tests.</li>
</ul>
<ul>
<li>Added assert_difference method.</li>
</ul>
<ul>
<li>Added ability to set/remove cookies before requests are made.</li>
</ul>
<ul>
<li>gem: mack_ruby_core_extensions 0.1.4</li>
</ul>
<pre>$ sudo gem install mack</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/03/27/release-041/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.081 seconds -->

