<?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>Cloudspace &#124; Blog &#187; Cucumber</title>
	<atom:link href="http://www.cloudspace.com/blog/category/cucumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cloudspace.com/blog</link>
	<description>All things cloudspacious</description>
	<lastBuildDate>Mon, 16 Jan 2012 22:58:52 +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>Creating a Reusable Dictionary of Steps in Cucumber</title>
		<link>http://www.cloudspace.com/blog/2009/02/18/creating-a-reusable-dictionary-of-steps-in-cucumber/</link>
		<comments>http://www.cloudspace.com/blog/2009/02/18/creating-a-reusable-dictionary-of-steps-in-cucumber/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 15:33:01 +0000</pubDate>
		<dc:creator>michaelorr</dc:creator>
				<category><![CDATA[agile development]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[Behavior Driven Development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test driven development]]></category>

		<guid isPermaLink="false">http://www.cloudspace.com/blog/?p=319</guid>
		<description><![CDATA[Corey and I have been using Cucumber to write our integration tests on our current project and I thought I&#8217;d share a tip with you that has made our lives so much easier. When making steps in Cucumber, try to &#8230; <a href="http://www.cloudspace.com/blog/2009/02/18/creating-a-reusable-dictionary-of-steps-in-cucumber/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Corey and I have been using <a href="http://wiki.github.com/aslakhellesoy/cucumber">Cucumber</a> to write our integration tests on our current project and I thought I&#8217;d share a tip with you that has made our lives so much easier.  When making steps in Cucumber, try to make them reusable.  The idea behind Cucmber&#8217;s integration tests is that you are creating a language to talk about (and test) your project. By creating a dictionary of reusable steps we cut down the amount of time it takes to write new features, and decrease the size of the testing language which makes it easier to wrap your head around it.  Here is a sample step definition that could be used to check for various http response codes</p>
<pre class="brush: ruby">
Then /^it should return a response code of &quot;(.+)&quot;$/ do |resp_code|
  response.code.should == resp_code
end
</pre>
<p>Then in your feature file you can use this step in multiple tests</p>
<pre class="brush: ruby">
Then it should return a response code of &quot;301&quot;
Then it should return a response code of &quot;200&quot;
</pre>
<p>Once you&#8217;ve built up a good step dictionary for your project you&#8217;ll absolutely squeal with delight the first time you write a new scenario using existing step definitions without opening the step definition file to make new steps.</p>
<p>As your library grows you&#8217;ll find yourself repeating the same series of steps in different scenarios.  When this happens, you have identified a common task sequence that can be combined into a single &#8220;meta step&#8221;. It is important to keep separate steps for each of these tasks (see <a href="http://wiki.github.com/aslakhellesoy/cucumber/conjunction-steps-antipattern">the Conjunction Step Anti-Pattern in the cucumber wiki</a>) but its also nice to create a single meta step to help DRY up your code.</p>
<p>As a simple example, lets say you notice that you often check for both a response code of 200 and a &#8220;successfully updated&#8221; message on the page with these two steps:</p>
<pre class="brush: ruby">
Then it should return a response code of &quot;200&quot;
And the response body should contain &quot;successfully updated&quot;
</pre>
<p>You could add this single step to wrap it up:</p>
<pre class="brush: ruby">
Then /^it should be a successful update$/ do
  Then &quot;it should return a response code of \&quot;200\&quot;&quot;
  And &quot;the response body should contain \&quot;successfully updated\&quot;&quot;
end
</pre>
<p>This is a simple and useful tip that&#8217;s easy to implement, and you can start using this today, even on a project that&#8217;s been around for a while. Keep your code simple, and yourself sane.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/43ba3c00-79b0-45b3-b3c5-2ee3b6fef193/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=43ba3c00-79b0-45b3-b3c5-2ee3b6fef193" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudspace.com/blog/2009/02/18/creating-a-reusable-dictionary-of-steps-in-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

