<?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>andy goundry &#187; bdd</title>
	<atom:link href="http://www.andygoundry.com/category/bdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygoundry.com</link>
	<description>web developer</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:01:06 +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>Debugging cucumber scenarios in Rubymine</title>
		<link>http://www.andygoundry.com/2012/02/01/debugging-cucumber-scenarios-in-rubymine/</link>
		<comments>http://www.andygoundry.com/2012/02/01/debugging-cucumber-scenarios-in-rubymine/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 15:52:10 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Rubymine]]></category>
		<category><![CDATA[bdd]]></category>

		<guid isPermaLink="false">http://www.andygoundry.com/?p=645</guid>
		<description><![CDATA[Debugging cucumber scenarios in Rubymine is wonderfully simple. Here&#8217;s how i do it:
Create a cucumber step that puts the app into debug mode and pops open the current page that&#8217;s being debugged

I use Rubymine&#8217;s gutter breakpoints, and I add the breakpoint after the save_and_open_page method call, so the page pops open before entering the debugger.
Insert [...]]]></description>
			<content:encoded><![CDATA[<p>Debugging cucumber scenarios in Rubymine is wonderfully simple. Here&#8217;s how i do it:</p>
<h3><span style="font-weight: normal;">Create a cucumber step that puts the app into debug mode and pops open the current page that&#8217;s being debugged</span></h3>
<p><img class="alignnone size-full wp-image-658" title="Screen Shot 2012-02-01 at 16.00.42" src="http://www.andygoundry.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-01-at-16.00.42.png" alt="Screen Shot 2012-02-01 at 16.00.42" width="258" height="62" /></p>
<p>I use Rubymine&#8217;s gutter breakpoints, and I add the breakpoint after the save_and_open_page method call, so the page pops open before entering the debugger.</p>
<h3><span style="font-weight: normal;">Insert the step into whichever scenario i wish to debug</span></h3>
<p><img class="alignnone size-full wp-image-647" title="Screen Shot 2012-02-01 at 15.43.25" src="http://www.andygoundry.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-01-at-15.43.25.png" alt="Screen Shot 2012-02-01 at 15.43.25" width="569" height="71" /></p>
<h3><span style="font-weight: normal;">Run the scenario in debug mode</span></h3>
<p><img class="alignnone size-full wp-image-649" title="Screen Shot 2012-02-01 at 15.48.36" src="http://www.andygoundry.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-01-at-15.48.36.png" alt="Screen Shot 2012-02-01 at 15.48.36" width="355" height="528" /></p>
<h3><span style="font-weight: normal;">Inspect the app&#8217;s objects in Rubymine&#8217;s Watches</span></h3>
<p><img class="alignnone size-full wp-image-648" title="Screen Shot 2012-02-01 at 15.36.27" src="http://www.andygoundry.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-01-at-15.36.27.png" alt="Screen Shot 2012-02-01 at 15.36.27" width="637" height="152" /></p>
<p>Pretty sweet! Super easy and extremely useful.</p>
<p>Rubymine&#8217;s a great app, and i&#8217;m just starting to scratch the surface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygoundry.com/2012/02/01/debugging-cucumber-scenarios-in-rubymine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Paperclip generated expiring S3 urls with RSpec, Cucumber and Timecop</title>
		<link>http://www.andygoundry.com/2011/12/21/using-cucumber-to-test-s3-expiring-urls/</link>
		<comments>http://www.andygoundry.com/2011/12/21/using-cucumber-to-test-s3-expiring-urls/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 07:07:15 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://www.andygoundry.com/?p=529</guid>
		<description><![CDATA[The need
I have a Rails app that is using Paperclip to generate expiring urls for files stored in S3. The urls are set to expire after 1 minute. As much as i trust Paperclip and Amazon, I need tests that prove that these generated urls do in fact expire on time, and that visitors to [...]]]></description>
			<content:encoded><![CDATA[<h2>The need</h2>
<p>I have a Rails app that is using Paperclip to generate expiring urls for files stored in S3. The urls are set to expire after 1 minute. As much as i trust Paperclip and Amazon, I need tests that prove that these generated urls do in fact expire on time, and that visitors to those files after they&#8217;ve expired are prevented from accessing the file.</p>
<h2 style="font-size: 1.5em;">Disclaimer</h2>
<p>This has been a bit of a rush, so no doubt i&#8217;ll refactor and tidy the code and this post laster today / in the week.</p>
<h2 style="font-size: 1.5em;">The solution</h2>
<p>I&#8217;ve used RSpec and Cucumber to check expiring urls that the system generates to ensure they expire successfully. RSpec simply checks that a generated url includes the Expires parameter and it&#8217;s value is set exactly to 60 seconds from now. Cucumber goes further than this by uploading files and checking if they are accessible before and after expiration.</p>
<h3><span style="color: #333399;"> RSpec to simply test that the expiration time generated for a link is correctly set to 1 minute<br />
</span></h3>
<p>This test simply asks the model containing the attachment (in this case an &#8220;Asset&#8221; model), how many seconds from now remain before the attachment expires.</p>
<p><strong>Spec</strong></p>
<blockquote><p>describe Asset do</p>
<p style="padding-left: 30px; "><strong> it &#8220;should return an attachment link that expires within 1 minute&#8221; do</strong></p>
<p style="padding-left: 60px;">asset = Factory.build(:asset)<br />
asset.seconds_until_attachment_expires.should == 60</p>
<p style="padding-left: 30px; ">end</p>
<p>end</p></blockquote>
<p>This depends on a few new methods in the Asset model class, which take care of extracting the Expires param from the expiring url, and comparing to Time.now.</p>
<p><strong>Asset Model Class</strong></p>
<p>First, we create an instance helper method that returns the number of seconds an object&#8217;s url has left before it expires</p>
<blockquote><p>def seconds_until_attachment_expires</p>
<p style="padding-left: 30px;">Asset.seconds_until_attachment_expires(expiring_attachment_url)</p>
<p>end</p></blockquote>
<p>I decided to pass the responsibility of calculating this number to a class method. I did this because the Cucumber tests need to request the same calculation for urls that were generated in the past. If they interacted with an instance of the Asset class, by default it would return a new url each time it was asked. So, rather than clutter up the instance method with a decision about whether to issue a new url or return an existing one, i simply passed the responsibility to the class. That seems to work for now, although I might refactor it later.</p>
<p>Next, we create the class level method that calculates time left until expiration. This accepts a url, meaning we can test urls generated now or in the past</p>
<blockquote><p>def self.seconds_until_attachment_expires(url)</p>
<p style="padding-left: 30px;">seconds = attachment_expiration_in_seconds_from_epoch(url) &#8211; Time.now.strftime(&#8221;%s&#8221;).to_i<br />
seconds.round</p>
<p>end</p></blockquote>
<p>This method simply strips the time from the generated url (via the attachment_expiration_in_seconds_from_epoch method) and rounds the value.</p>
<blockquote><p>def self.attachment_expiration_in_seconds_from_epoch(url)</p>
<p style="padding-left: 30px;">url.split(&#8221;&amp;&#8221;).second.split(&#8221;=&#8221;).last.to_i</p>
<p>end</p></blockquote>
<p>Clearly, this is tightly coupled to the format of the generated url string, so a cleaner way should be sought. However, for now, this method is only used in the tests and it does work, so it&#8217;ll do for the moment.</p>
<p>Finally, to ensure that Rspec, Cucumber and the app all interact with a url generated exactly 60 seconds from now, we create a model instance method that generates the link. All requests for the link call this method.</p>
<blockquote><p>def expiring_attachment_url</p>
<p style="padding-left: 30px;">attachment.expiring_url(60)</p>
<p>end</p></blockquote>
<h3 style="font-size: 1.17em;"><span style="color: #333399;">Cucumber to test actual file access via the browser</span></h3>
<p>Cucumber takes things 1 step further. It interacts with all the same methods that we created on the Asset model, but also goes off and uploads attachments and then tries to access them before and after they&#8217;ve expired. We use <a href="http://www.google.co.uk/url?sa=t&amp;rct=j&amp;q=timecop%20gem&amp;source=web&amp;cd=1&amp;ved=0CCEQFjAA&amp;url=https%3A%2F%2Fgithub.com%2Fjtrupiano%2Ftimecop&amp;ei=CarxTpfiJMLLswbLlM3mDw&amp;usg=AFQjCNHx9MgEnBzIw0ysdxhOMlxC40j_4Q">Timecop</a> to create expired urls, and a Cucumber <em>before</em> hook to ensure all scenarios run from the current time by default.</p>
<p><strong>Scenarios</strong></p>
<blockquote><p>@selenium<br />
<strong>Scenario: Viewing an active attachment on an object</strong></p>
<p style="padding-left: 30px;"><strong> </strong>Given some object has been created and a plain text file attached<br />
When I visit the object&#8217;s attachment url<br />
Then I should see the contents of the uploaded attachment<br />
And I should not see &#8220;Request has expired&#8221;</p>
<p>@selenium<br />
<strong>Scenario: Viewing an expired attachment on an object</strong></p>
<p style="padding-left: 30px;"><strong> </strong>Given some object has been created and a plain text file attached<br />
When I visit the object&#8217;s attachment url after it has expired<br />
Then I should not see the contents of the uploaded attachment<br />
And I should see &#8220;Request has expired&#8221;</p>
</blockquote>
<p><strong>features/support/hooks.rb</strong></p>
<blockquote><p>Before do</p>
<p style="padding-left: 30px;">Timecop.return</p>
<p>end</p></blockquote>
<p>NB: For the sake of completeness (even though we&#8217;re not calling Timecop from our Rspec specs), to be completely satisfied that Timecop isn&#8217;t affecting our specs in any unexpected way, we add the same to spec_helper.rb too:</p>
<p><strong>spec/spec_helper.rb</strong></p>
<p><strong><span style="font-weight: normal; "> </span></strong></p>
<blockquote><p>config.before do</p>
<p style="padding-left: 30px;">Timecop.return</p>
<p>end</p></blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 776px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">config.before do</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 776px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Timecop.return</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 776px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">end</div>
<p><strong>steps</strong></p>
<p>This is where Timecop offers a wonderfully simple way of generating expired urls.</p>
<blockquote><p><strong>And /^I visit the question&#8217;s attachment url after it has expired$/ do</strong></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;"><span style="color: #008080;"><span style="color: #99ccff;"><span style="color: #ff9900;"><span style="color: #333399;"><strong>#First, go back in time 2 minutes and generate the expiring url, and make sure it&#8217;s set to expire in 1 minute</strong><br />
</span> </span> </span> </span> </span> Timecop.freeze(Time.now &#8211; 2.to_i.minutes) do</p>
<p style="padding-left: 60px;">@url = current_object.asset.expiring_attachment_url<br />
Asset.attachment_expires_in(@url).should == 60</p>
<p style="padding-left: 30px;">end</p>
<p style="padding-left: 30px;"><strong><span style="color: #3366ff;"><span style="color: #008080;"><span style="color: #99ccff;"><span style="color: #ff9900;"><span style="color: #333399;"> #Next, return to the current time and make sure the previously generated expiring url has now been expired for 1 minute<br />
</span> </span> </span> </span> </span></strong> Timecop.return<br />
Asset.attachment_expires_in(@url).should == -60</p>
<p style="padding-left: 30px;"><strong><span style="color: #3366ff;"><span style="color: #008080;"><span style="color: #99ccff;"><span style="color: #ff9900;"><span style="color: #333399;"> #Finally, go visit the expired url<br />
</span> </span> </span> </span> </span></strong> visit @url</p>
<p>end</p></blockquote>
<p>When run, cucumber correctly reports that expired urls result in the user seeing the message &#8220;Request has expired&#8221;, and non-expired urls correctly provide access to the uploaded file.</p>
<h2 style="font-size: 1.5em;">Summary</h2>
<p>Although a rough and ready solution, and most likely needing refactoring, it does provide us with a way to test expiration of uploads to S3.</p>
<p>I hope you found this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygoundry.com/2011/12/21/using-cucumber-to-test-s3-expiring-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Merb, Cucumber and Webrat (and friends) on Snow Leopard</title>
		<link>http://www.andygoundry.com/2009/09/04/setting-up-merb-cucumber-and-webrat-on-snow-leopard-some-good-some-bad/</link>
		<comments>http://www.andygoundry.com/2009/09/04/setting-up-merb-cucumber-and-webrat-on-snow-leopard-some-good-some-bad/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 14:36:06 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Merb]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Webrat]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.andygoundry.com/?p=428</guid>
		<description><![CDATA[
My upgrade to Snow Leopard killed my Merb, Cucumber and Webrat setup so i had to start afresh. That was the bad. The good is that some manual hacks that were required in Leopard are no longer necessary, meaning I can rely on direct gem installations.
Here&#8217;s what i did:

Install Ruby and Gems
Follow instructions on http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/
Install [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>My upgrade to Snow Leopard killed my Merb, Cucumber and Webrat setup so i had to start afresh. That was the bad. The good is that some manual hacks that were required in Leopard are no longer necessary, meaning I can rely on direct gem installations.</p>
<p>Here&#8217;s what i did:</p>
<ol>
<li><strong>Install Ruby and Gems<br />
<span style="font-weight: normal; ">Follow instructions on <a href="http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/">http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/</a></span></strong></li>
<li><strong>Install merb, rspec, cucumber, merb_cucumber and mongrel and dependencies<br />
<span style="font-weight: normal; ">sudo gem install merb rspec cucumber roman-merb_cucumber mongrel term-ansicolor treetop diff-lcs nokogiri do_sqlite3</span></strong></li>
<li><strong>Install webrat<br />
<span style="font-weight: normal;">sudo gem install hoe hpricot webrat</span></strong></li>
<li><strong><span style="font-weight: normal;"><strong>Fix Firefox bug with Snow Leopard<br />
<span style="font-weight: normal;">For some reason the libsqlite3.dylib  library in FireFox 3.5.2 is out of date and breaks cucumber under Snow Leopard. Thankfully, it&#8217;s a simple fix:<br />
mv /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib.orig<br />
cp /usr/lib/libsqlite3.dylib /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib</span></strong></span></strong></li>
<li><strong><span style="font-weight: normal;"><strong><span style="font-weight: normal;"><strong>Install Selenium<br />
<span style="font-weight: normal;">sudo gem install Selenium<br />
sudo gem install selenium-client</span></strong></span></strong></span></strong></li>
<li><strong>Install the textmate cucumber bundle<br />
<span style="font-weight: normal;"><a href="http://github.com/bmabey/cucumber-tmbundle/tree/master">http://github.com/bmabey/cucumber-tmbundle/tree/master</a></span></strong></li>
</ol>
<p><strong>Deprecated Instructions on Snow Leopard that were required on Leopard</strong></p>
<p>The following ugly hacks were required on Leopard with it&#8217;s default Ruby installation. These are no longer required (at least on my machine) on Snow Leopard:</p>
<p><span style="text-decoration: underline;">Manual hack of Selenium</span></p>
<p>http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium</p>
<p>As the instructions recommended replacing the Selemium RC jar file () in the installed gem with one from the Selenium website, i had to find out where the gem had installed. Thankfully, gem -h pointed me toward gem help commands and from there i ran gem environment &#8211; This told me where gems are installed locally and i found that Selemium RC had been installed into /Library/Ruby/Gems/1.8/gems/Selenium-1.1.14/ I replaced as advised and then ran selenium from within the app root and all worked fine, using the replacement. I then downloaded and ran the test selenium code from http://github.com/aslakhellesoy/cucumber/tree/master/examples/selenium running selenium in a different console and then running cucumber examples/selenium/features/ . It worked a treat and booted up selenium as required. Great!</p>
<p><span style="text-decoration: underline;">Manual hack installation of webrat</span></p>
<p>Download http://github.com/gwynm/webrat/tree/master tar file. Git clone doesn&#8217;t work</p>
<p>sudo gem install hoe hpricot<br />
cd downloaded and untarred file<br />
rake gem<br />
sudo gem install pkg/webrat-0.2.1.gem</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.andygoundry.com/2009/09/04/setting-up-merb-cucumber-and-webrat-on-snow-leopard-some-good-some-bad/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Presenting BDD Story-driven delivery to project and account managers</title>
		<link>http://www.andygoundry.com/2009/04/15/presenting-bdd-story-driven-delivery-to-project-and-account-managers/</link>
		<comments>http://www.andygoundry.com/2009/04/15/presenting-bdd-story-driven-delivery-to-project-and-account-managers/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 18:16:45 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://www.andygoundry.com/?p=351</guid>
		<description><![CDATA[Today, i had the true pleasure of presenting my view of how BDD stories offer real business value to project delivery, quality and to the lives of everyone on a software delivery project. 
Part 1: Collectively clarify what happens on projects now (on projects that do not use stories)
It was a highly interactive session and [...]]]></description>
			<content:encoded><![CDATA[<p>Today, i had the true pleasure of presenting my view of how BDD stories offer real business value to project delivery, quality and to the lives of everyone on a software delivery project. </p>
<p><strong>Part 1: Collectively clarify what happens on projects now (on projects that do not use stories)</strong></p>
<p>It was a highly interactive session and i first asked attendees to collectively draw on a whiteboard the project process as they saw it, with all of the project&#8217;s actors, products and interactions.</p>
<p>What was drawn resembled a kind of mashup of a <a href="http://www.agilemodeling.com/artifacts/activityDiagram.htm">UML activity diagram with swim lanes</a> &#038; a gantt chart. It showed what the individual actors in the process did and when, and who fed into who in the process.</p>
<p><strong>Part 2: Clarify what documents are written and the associated risks and costs</strong></p>
<p>When the whiteboard was complete, I asked the attendees to consider a number of things:</p>
<ol>
<li>At what points during the process are documents produced and by who?</li>
<li>Of those documents produced, which are directly focused on the business and user requirements?</li>
<li>Of the many producers of those documents, which of these producers had their focus on the business and user requirements?</li>
<li>Of the many documents produced, which were open to interpretation and translation?</li>
<li>What are the perceived risks of having so many documents and periods of documentation translation?</li>
</ol>
<p>When this work was complete, a few points became clear to the group:</p>
<ol>
<li>The project team, as defined on the whiteboard, was greatly separated into areas of expertise and each was concerned about their area of expertise</li>
<li>Interactions between actors were mostly through written documents</li>
<li>Few actors following this project process retained a direct focus on the business and end user requirements</li>
<li>A lot of documentation was being written and much of it was being duplicated, at times to protect actors within the process</li>
<li>Vast amounts of document interpretation and translation was going on to produce each document</li>
</ol>
<p><strong>Part 3: Consider stories</strong></p>
<p>After this part of the session was complete, i gave some examples of the wonderfully simple <a href="http://dannorth.net/introducing-bdd">story DSL</a> and then suggested that many of these documents could be replaced by stories and scenarios:</p>
<ol>
<li>I explained that stories can be used to clarify both high-level requirements and detailed solution definitions. I described how stories can be expanded through the use of scenarios.</li>
<li>I described how everyone on the project, including the client, can understand the wonderfully simple DSL and contribute to the bank of stories.</li>
<li>I then came in with the ace <img src='http://www.andygoundry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Stories can be used to drive automated browser tests! Man, <strong>they fell off their seats at the point!</strong></li>
</ol>
<p>It was an awesome session. A lot was discussed and understood.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygoundry.com/2009/04/15/presenting-bdd-story-driven-delivery-to-project-and-account-managers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

