<?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>threehv &#187; cucumber</title>
	<atom:link href="http://www.3hv.co.uk/blog/tag/cucumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3hv.co.uk/blog</link>
	<description>precision engineering for your website</description>
	<lastBuildDate>Fri, 13 Jan 2012 16:18:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>It happens to the best of us</title>
		<link>http://www.3hv.co.uk/blog/2009/10/05/it-happens-to-the-best-of-us/</link>
		<comments>http://www.3hv.co.uk/blog/2009/10/05/it-happens-to-the-best-of-us/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 16:21:53 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[Bug-Free Code]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Writing Reliable]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=581</guid>
		<description><![CDATA[We just had some customers report a bug. Not good. We didn&#8217;t get an exception email. All the tests passed. We couldn&#8217;t see anything untoward in the log files. But it was there. We could reproduce it, both in staging and in production. Not good at all. But the weirdest thing was we couldn&#8217;t figure [...]]]></description>
			<content:encoded><![CDATA[<p>We just had some customers report a bug. Not good. We didn&#8217;t get an exception email. All the tests passed. We couldn&#8217;t see anything untoward in the log files.  But it was there. We could reproduce it, both in staging and in production. Not good at all. </p>
<p>But the weirdest thing was we couldn&#8217;t figure out the cause. Well I could see why the code was failing (after adding some extra log messages). But &#8216;git blame&#8217; said those lines of code were unchanged in twelve months.  Why hadn&#8217;t people complained before?  Why hadn&#8217;t we <em>noticed</em> it?</p>
<p>After much hunting through log files we found the point when the feature last worked. It coincided with a deployment. That deployment was our Rails 2.3.4 forms vulnerability fix. And the bug was in a form &#8211; a missing form parameter that earlier versions of Rails ignored, the newer Rails was choking on.  </p>
<p>But why didn&#8217;t the tests catch it?  </p>
<p>After more hunting I saw that the Cucumber test that exercised the form didn&#8217;t have a &#8220;When I press the Update button&#8221; step.  And the subsequent tests were passing, even though the update button hadn&#8217;t been pressed.  </p>
<p>So I added the step in and made the feature pass.  Then deployed it as an emergency fix.  </p>
<p>However, what are the lessons to learn here (as there are always some)? </p>
<ul>
<li>Firstly, testing cannot catch everything.  </li>
<li>Secondly, the cracks in your tests are where the bugs are.  </li>
<li>Thirdly, we probably need some sort of peer review for tests.  I feel that this is more important than for code, because once the tests are right you can refactor the code without worry.  </li>
<li>Fourthly, you really need to <strong>log everything</strong>.  Absolutely everything.  Don&#8217;t worry about your huge log files &#8211; that&#8217;s what `logrotate` is for.  Get it written down so that one time when you have an obscure bug, you&#8217;ll be able to find it easily.  </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/10/05/it-happens-to-the-best-of-us/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Cucumber to estimate a project</title>
		<link>http://www.3hv.co.uk/blog/2009/05/15/using-cucumber-to-estimate-a-project/</link>
		<comments>http://www.3hv.co.uk/blog/2009/05/15/using-cucumber-to-estimate-a-project/#comments</comments>
		<pubDate>Fri, 15 May 2009 16:39:45 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Designing Great Software]]></category>
		<category><![CDATA[Managing Successful Projects]]></category>
		<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[estimates]]></category>
		<category><![CDATA[project planning]]></category>
		<category><![CDATA[requirements gathering]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=521</guid>
		<description><![CDATA[Writing estimates up-front is a really tricky part of client work. From the customer&#8217;s point of view it&#8217;s pretty essential. You need to know how much you are spending before the work begins so you don&#8217;t get stung. From the developer&#8217;s point of view it&#8217;s pretty difficult to do because you don&#8217;t know how long [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.3hv.co.uk/blog/wp-content/uploads/2009/05/281211_6743jpg-300x225.jpg" alt="Invoice" title="Invoice" width="300" height="225" class="alignright size-medium wp-image-524" style="margin: 4px" />Writing estimates up-front is a really tricky part of client work.  </p>
<p>From the customer&#8217;s point of view it&#8217;s pretty essential.  You need to know how much you are spending before the work begins so you don&#8217;t get stung.    </p>
<p>From the developer&#8217;s point of view it&#8217;s pretty difficult to do because you don&#8217;t know how long things will take until you know what you&#8217;re building.  And you don&#8217;t know the details of what you are building until they become apparent, which is normally while you are doing the work.  </p>
<p>For this particular client I wanted to get this piece of work out of the way as quickly as possible and the requirements were deceptively complicated.  As trying to deal with intangibles is a recipe for disaster, and time was short, I was pretty sure that whatever estimate I came up with would be totally inaccurate.  </p>
<p>So to deal with the intangibles I thought I may as well get stuck in with the actual work.  And what&#8217;s the first thing that I do?  Write a <a href="http://cukes.info">cucumber</a> story.  </p>
<p>I went through the requirements documents (which after weeks of to and fro were actually quite detailed and refined) and broke it down into four features, each with a number of scenarios.  Each scenario was then broken down into individual steps &#8211; however, I did not write any step definition (ruby) files.  This is cucumber as customer documentation, not as integration testing.  </p>
<p>We agreed that the features met the requirements (the client was very impressed with the level of detail and the clarity that cucumber offered) and I simply went through each feature, scenario and step and came up with a price for the step individually.  It&#8217;s still guesswork, but it&#8217;s guesswork on a small scale, so you&#8217;re less likely to be way off.  Total the lot and there&#8217;s your estimate.  </p>
<p>And even better, once the client has agreed the price and you&#8217;ve started development, you&#8217;ve got a development plan, a measure of progress and proof that it all works &#8211; all just a simple <tt>rake features</tt> away.  </p>
<p><small>Image by <a href="http://www.sxc.hu/profile/lemon_drop">lemon drop</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/05/15/using-cucumber-to-estimate-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: make it easier to debug your full-stack acceptance tests</title>
		<link>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/</link>
		<comments>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 09:40:29 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[acceptance tests]]></category>
		<category><![CDATA[Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[specifying]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[webrat]]></category>
		<category><![CDATA[Writing Reliable]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=439</guid>
		<description><![CDATA[One of the issues when using Selenium or Watir to power your full-stack acceptance testing (apart from the time it takes for the test suite to run), is that stuff happens within your browser, fails and then Cucumber happily moves on to the next test before you get a chance to look at what went [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_443" class="wp-caption alignright" style="width: 209px"><img src="http://www.3hv.co.uk/blog/wp-content/uploads/2009/03/959622_spanners_2.jpg" alt="Spanner in the works" title="Testing" width="199" height="300" class="size-full wp-image-443" /><p class="wp-caption-text">Spanner in the works</p></div>One of the issues when using Selenium or Watir to power your full-stack acceptance testing (apart from the time it takes for the test suite to run), is that stuff happens within your browser, fails and then Cucumber happily moves on to the next test before you get a chance to look at what went wrong.  </p>
<p>If you are just using plain old Webrat you can pepper your code with <tt>puts</tt> statements so you can check the value of variables, the existence of HTML elements and the flow of code as it happens.  But with Selenium or Watir, you need to run your app separately to Cucumber, normally in a hidden, background, process, so the output of your <tt>puts</tt> statements is lost in the ether (or an empty pipe).  </p>
<p>After having a particularly annoying and hard to trace bug, that was related to an interaction between form content and javascript, I came up with an extremely simple debugging tool.  </p>
<p>Just add the following into one of your steps files: </p>
<pre><code>When /^I pause$/ do
  STDIN.gets
end
</code></pre>
<p>Then, find the feature that is causing you grief and insert a &#8220;when I pause&#8221; step at the appropriate time.  </p>
<p><code>When I do this<br />
And I do that<br />
<strong>And I pause</strong><br />
And I press "Save"<br />
Then I see my newly created object<br />
</code></p>
<p>Cucumber will power your app, poking it until it gets to the &#8220;when I pause&#8221; step.  It will then pause, waiting on STDIN for you to hit return &#8211; giving you time to open your inspector window and poke around in the form as the tests see it.  </p>
<p>In this particular case, my steps file had an incorrectly named element within it &#8211; all it took was an inspection of the element in question and I saw the error.  Hours of frustration wiped out by one of the simplest commands there is.  </p>
<p><small>Spanners by <a href="http://www.sxc.hu/photo/959622">woodsy</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The trouble with mocks (or design versus acceptance)</title>
		<link>http://www.3hv.co.uk/blog/2009/03/12/the-trouble-with-mocks-or-design-versus-acceptance/</link>
		<comments>http://www.3hv.co.uk/blog/2009/03/12/the-trouble-with-mocks-or-design-versus-acceptance/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 05:26:02 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[demeters revenge]]></category>
		<category><![CDATA[luke redpath]]></category>
		<category><![CDATA[mock objects]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[specifying]]></category>
		<category><![CDATA[Writing Reliable]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=426</guid>
		<description><![CDATA[I had the pleasure of speaking to Luke Redpath the other day. I started off by thanking him for his Demeter&#8217;s Revenge plugin, which is one of the first things I install on a new project. He said he didn&#8217;t use it much any more, as he doesn&#8217;t do mocking, except during the design process. [...]]]></description>
			<content:encoded><![CDATA[<p>I had the pleasure of speaking to <a href="http://www.lukeredpath.co.uk/">Luke Redpath</a> the other day.  </p>
<p>I started off by thanking him for his <a href="http://www.lukeredpath.co.uk/blog/demeters-revenge.html">Demeter&#8217;s Revenge</a> plugin, which is one of the first things I <a href="http://github.com/caius/demeters_revenge/tree/master">install</a> on a new project. He said he didn&#8217;t use it much any more, as he doesn&#8217;t do mocking, except during the design process.  This surprised me, but thinking about it, the distinction between what your different types of tests <em>are for</em> is an important one.  </p>
<p>The most important part of using mocks is their value in designing your class&#8217;s public API.  You start with a <a href="http://cukes.info/">cucumber</a> feature (your acceptance test) and as you are implementing it, fill in specs for each component in turn.  As features are defined in terms of the user interface, you start by specifying and designing your view and controller.  The controller needs to interact with a model.  And this is where mocking comes into its own.  </p>
<pre><code>
describe WotsitPokesController
  it "should poke a wotsit" do
    on_posting_to :create, :id => '1' do
      @wotsit = mock_model Wotsit
      Wotsit.should_receive(:find).with('1').and_return(@wotsit)
      @wotsit.should_receive(:poke).and_return(true)
    end
    response.should redirect_to(edit_wotsit_path(@wotsit))
    flash[:notice].should == 'Your wotsit has been poked'
  end
</code></pre>
<p>(this uses the <a href="http://github.com/brightbox/rspec-rails-extensions/tree/master">RSpec-Rails Extensions</a> to tidy up the specification)</p>
<p>Whatever @wotsit.poke does, when you are mocking, it is in your interests to encapsulate its behaviour within a single method.  Otherwise you end up writing tons of &#8220;fake&#8221; code within your spec, which makes the tests brittle and hard to maintain.  </p>
<p>A small housekeeping note; as soon as your controller spec references @wotsit.poke, you need to go to your model spec and add:</p>
<pre><code>
  it "should poke itself"
</code></pre>
<p>A pending specification, just as a reminder that you&#8217;ve got a method to implement in a few minutes time.  </p>
<p>But Luke had started doing full-stack testing alone; using <a href="http://thoughtbot.com/projects/shoulda/">shoulda</a> (with its nested contexts) to write acceptance tests, rather than <a href="http://rspec.info">RSpec</a> and mocking.  </p>
<p>I&#8217;m not so sure about this. His reason was the brittleness of mocked tests.  Agreed, it can be dangerous; if you rename the &#8220;poke&#8221; method on your Wotsit, your controller spec will still pass.  <strong>But</strong>, crucially, your cucumber story (or shoulda integration test) will not.  </p>
<p>So I guess the point to make here is that specifying with mocks alone can be a <em>bad idea</em>.  You need a full-stack test to catch the stuff that &#8220;falls between the cracks&#8221;, the proof that your application does what it is supposed to do.  </p>
<p>Can you just forego the mocks completely?  I don&#8217;t think so; they are too valuable during the exploration/design phase.  </p>
<p>Should you just get rid of the mocks once your acceptance test is passing?  Luke says yes.  I&#8217;m still undecided, but certainly am tending towards no.  </p>
<p>So, what&#8217;s your take?  Are mocks too brittle to be used in long term development?  Or, coupled with an acceptance test, is the value they give so great we need to keep them in our test suite?  </p>
<p>(interestingly, since I drafted this post, Pat Maddox has also <a href="http://www.patmaddox.com/blog/you-probably-dont-get-mocks">written about much the same subject with a similar outcome</a> &#8211; including Matt Wynne stating &#8220;<cite>Acceptance tests are for regression coverage, unit tests are for design</cite>&#8221; in the comments, although Pat himself says you can delete the specs once the design is done).  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/03/12/the-trouble-with-mocks-or-design-versus-acceptance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cucumber and WATIR: kick-starting your testing</title>
		<link>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/</link>
		<comments>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 09:52:50 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Designing Great Software]]></category>
		<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=360</guid>
		<description><![CDATA[I think Cucumber is fast becoming indispensable for my testing. The point of it is that you can write documentation that your client understands and then prove that the application does what it says. When coupled with WATIR you can show that it really works in an actual browser &#8211; you can even show it [...]]]></description>
			<content:encoded><![CDATA[<p>I think <a href="http://wiki.github.com/aslakhellesoy/cucumber">Cucumber</a> is fast becoming indispensable for my testing.  The point of it is that you can write documentation that your client understands and then prove that the application does what it says.  When coupled with <a href="http://wtr.rubyforge.org/">WATIR</a> you can show that it really works in an actual browser &#8211; you can even show it in Internet Explorer, Firefox and Safari.  </p>
<p>There are a number of issues with using WATIR &#8211; the main one being speed &#8211; as WATIR scripts the browser, an extensive test suite will take a long time to run.  </p>
<p>But my first hurdle was actually getting the code running.  Unlike using Cucumber with <a href="http://wiki.github.com/brynary/webrat">Webrat</a>, where your Cucumber steps have access to your Rails code (so you can play around with the response object), with WATIR you run the application in a separate process and then poke the browser in the same way a real user would.  Of course, unlike Webrat, you get to test your Javascript too.  </p>
<p>However, I didn&#8217;t want to have to remember to start my application before running the tests (and probably forgetting to put it into the test environment or running on the wrong port) &#8211; so I came up with the following for your features/support/env.rb.  </p>
<pre><code>
system 'rake db:test:clone'
system 'rm log/test.log'
system 'ruby script/server -p 3001 -e test -d'

at_exit do
  system "kill `ps aux | grep mongrel_rails | grep -e '-p 3001' | grep -v grep | awk '{ print $2 }'`"
end

Before do
  @browser = Watir::Safari.new
  @browser.set_fast_speed
  @base_url = 'http://localhost:3001'
end
</code></pre>
<p>This clones your development database, gets rid of the test log (as we&#8217;ll need to look through that to track down any errors, so we want to keep it small) and then starts your app in test mode on port 3001 (so it doesn&#8217;t clash with the version you&#8217;ve already got open in development).  The Before clause sets up WATIR and configures a base url that my steps use elsewhere.  And the at_exit hook looks for the server we started and kills it.  </p>
<p>Next step is to add a platform instruction &#8211; so you can choose to test with Safari, Firefox (if I can ever get the Firewatir plugin installed) and Internet Explorer (where I guess the kill statement will need a bit of alteration).  </p>
<p>An alternative is to tell mongrel to start and write a pidfile to a known place, and then replace the ps/grep line with: </p>
<pre><code>
  pid = File.read(File.expand_path(RAILS_ROOT + "/log/mongrel.pid")).chomp
  `kill #{pid}`
</code></pre>
<p>Thanks to <a href="http://caius.name/">Caius</a> for that version.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acceptance Testing in Ruby, Rails, RSpec and Cucumber</title>
		<link>http://www.3hv.co.uk/blog/2008/11/21/acceptance-testing-in-ruby-rails-rspec-and-cucumber/</link>
		<comments>http://www.3hv.co.uk/blog/2008/11/21/acceptance-testing-in-ruby-rails-rspec-and-cucumber/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 18:16:13 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Beautiful Code]]></category>
		<category><![CDATA[Designing Great Software]]></category>
		<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=328</guid>
		<description><![CDATA[I&#8217;ve written up a new post at the Brightbox blog detailing how we are using RSpec and Cucumber to build acceptance tests for the next generation Brightbox systems.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written up a new post at the <a href="http://blog.brightbox.co.uk/posts/using-rspec-cucumber-and-user-stories-to-build-our-internal-systems">Brightbox blog</a> detailing how we are using <a href="http://rspec.info/">RSpec</a> and <a href="http://github.com/aslakhellesoy/cucumber/tree/master">Cucumber</a> to build acceptance tests for the next generation Brightbox systems.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2008/11/21/acceptance-testing-in-ruby-rails-rspec-and-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

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

