<?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>Blog &#124; Rubyyot &#187; cucumber</title>
	<atom:link href="http://blog.rubyyot.com/tag/cucumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rubyyot.com</link>
	<description>Programming, Pragmatism and Getting By in the World</description>
	<lastBuildDate>Wed, 24 Mar 2010 00:14:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting a project off the ground with TDD and Cucumber</title>
		<link>http://blog.rubyyot.com/2009/06/getting-a-project-off-the-ground-with-tdd-and-cucumber/</link>
		<comments>http://blog.rubyyot.com/2009/06/getting-a-project-off-the-ground-with-tdd-and-cucumber/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 05:17:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[starting a project]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=659</guid>
		<description><![CDATA[RSimpy
I am currently wrapping up an initial release of a new gem that wraps the Simpy.com API.  I like social bookmarking and used delicious for years before switching to Simpy as my primary service.  Simpy is not the biggest online bookmarking service, but I&#8217;ve decided to use it for reasons I will outline [...]]]></description>
			<content:encoded><![CDATA[<h3>RSimpy</h3>
<p>I am currently wrapping up an initial release of a new gem that wraps the <a href="http://simpy.com/" title="" target="_blank" rel="user">Simpy.com</a> API.  I like social bookmarking and used delicious for years before switching to Simpy as my primary service.  Simpy is not the biggest online bookmarking service, but I&#8217;ve decided to use it for reasons I will outline in another post.  In any case I&#8217;ve put together a gem that wraps the API with the help of Httparty.  It actually turned out much simpler than I expected it to be, httparty did all of the heavy lifting, but again that is for another post.</p>
<p>So, I have a functioning gem for Simpy, now I want to make something useful with it.  The reason I made the gem was to simplify my bookmarking which is overall a mess on multiple workstations in multiple locations.  Since I&#8217;ve recently been getting familia with cron, I&#8217;ve decided to make a script to store urls locally and use <a href="http://en.wikipedia.org/wiki/Cron" title="cron" target="_blank" rel="definition">cron</a> to run a script that pushes a file of pages to Simpy.</p>
<p>As I touched on briefly, I&#8217;ve been unhappy with all my previous bookmarking solutions thus far.  This time I want to make it, dead simple.  I don&#8217;t want to have to enter any additional information if I don&#8217;t want to, just a url and have it go on it&#8217;s merry way.  However to post the link, I will need to at least have the page title.  Pulling a page title from a url is really outside of the scope of RSimpy.  Ruby makes it fairly simple to do, but I don&#8217;t want to isolate the functionality to a script.  Ruminate to the rescue, but what is Ruminate?</p>
<h3>Ruminate</h3>
<p>Well the answer to that question is that I&#8217;m not really sure.  A few months back, I made a gem with jeweler called ruminate with the description  &#8220;Extracts statistics from html documents&#8221;.  Actually, I&#8217;m not really sure what I originally had in mind when I setup this gem, but it will be useful now since I want to extract at least the page title.  Once I get the ability to extract a page title, I can make a script that is simply glue code to put Ruminate together with RSimpy and voila!</p>
<h3>Bootstrapping the project</h3>
<p>I have a vague idea of something that I want Ruminate to do, that is I want to be able to query a url to return the title of the page.  It&#8217;s obviously not the entire purpose of the gem, but I&#8217;m sure that will be lots of other bits that will come together in time. </p>
<p>The question is, How do I kickstart this project with TDD to get it off the ground?</p>
<h3>Programming by Intention</h3>
<p><a title="programming by intention" target="blank" href="http://www.hans-eric.com/2007/09/05/tools-of-the-effective-developer-personal-planning/">Programming by intention</a> is the practice of writing code, while pretending that any methods or classes you might reference already exist and operate in the way that you reference them.  It&#8217;s a great way of uncovering a simple intuative API that you might otherwise would have missed.</p>
<p>I&#8217;ve seen it described in two books, first in <a href="http://www.pragprog.com/titles/bmsft/everyday-scripting-with-ruby"  target="_blank" title="Everyday scripting with Ruby" rel="book I've read"><em>Everyday Scripting with Ruby</em></a>, from The Pragmatic Bookshelf. Secondly, it&#8217;s used in an excellent book I&#8217;m currently reading called  <a href="http://www.javalobby.org/java/forums/t102176.html" target="_blank" title="Test Driven" rel="book I've read"><em>Test Driven</em></a> from Manning.</p>
<p>  There are <a href="http://bradwilson.typepad.com/blog/2009/04/its-not-tdd-its-design-by-example.html" target="_blank">a number</a> <a href="http://www.hanselman.com/blog/HanselminutesPodcast146TestDrivenDevelopmentIsDesignTheLastWordOnTDD.aspx" target="_blank">of sources</a> <a href="http://blog.jpboodhoo.com/DesignVsCodingHowMuchIsTooMuch.aspx" target="_blank">stating that</a> <a href="http://weblogs.asp.net/rosherove/archive/2007/10/08/the-various-meanings-of-tdd.aspx" target="_blank">TDD</a> <a href="http://blog.codiceplastico.com/?p=181" target="_blank">is about design first</a> <a href="http://davybrion.com/blog/2008/08/introducing-tdd-how-would-you-do-it/" target="_blank">and automated testing</a> <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/04/22/should-you-tdd-when-flying-solo.aspx" target="_blank">is a nice by-product</a>.  In my limited experience with TDD, programming by intention is the crux of this design, and by extension the primary purpose of TDD.</p>
<h3>Cucumber</h3>
<p>One of the things that I really like about cucumber is that you can plainly state your intent and important bits of your feature focused domain in plain English and match that up to executable code. To describe the ability of Ruminate to grab the title of a url, I made the following test:</p>

<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;">Feature: Get Page Title
  In to get the page title
  A user of ruminate
  Will request a page title
&nbsp;
  Scenario: Requesting the title of a page from the page
    Given the url &quot;http://www.google.com&quot;
    When I execute the request
    Then the &quot;title&quot; should be &quot;Google&quot;</pre></div></div>

<p>I let cucumber auto-generate the regular expression blocks and came up with the following steps:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^the url <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>url<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#0066ff; font-weight:bold;">@url</span> = url
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I execute the request$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  query = <span style="color:#996600;">&quot;Select title from #{@url};&quot;</span>
  <span style="color:#0066ff; font-weight:bold;">@result</span> = chew query
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> should be <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>msg, value<span style="color:#006600; font-weight:bold;">|</span>
  assert_equal value, <span style="color:#0066ff; font-weight:bold;">@result</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As you can see I&#8217;ve decided to try out a sql like syntax for the tool.  I thought it sounded interesting, we&#8217;ll see if I keep it. In any case, I now need to make this test pass with the help of a mixin, that I&#8217;m including in features/support/env.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># features/support/env.rb</span>
<span style="color:#ff6633; font-weight:bold;">$LOAD_PATH</span>.<span style="color:#9900CC;">unshift</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../../lib'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ruminate'</span>
<span style="color:#9966CC; font-weight:bold;">include</span> Ruminate
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test/unit/assertions'</span>
&nbsp;
World<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Test::Unit::Assertions</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># lib/ruminate.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'query_parser'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'engine'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> Ruminate
  <span style="color:#9966CC; font-weight:bold;">def</span> chew query
    parser = <span style="color:#6666ff; font-weight:bold;">Ruminate::QueryParser</span>.<span style="color:#9900CC;">new</span>
    query_object = parser.<span style="color:#9900CC;">parse</span> query
    engine = <span style="color:#6666ff; font-weight:bold;">Ruminate::Engine</span>.<span style="color:#9900CC;">new</span>
&nbsp;
    engine.<span style="color:#9900CC;">execute</span> query_object
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Here I&#8217;ve used the mixin to split the method into to operations and encapsulated each of these into a class.  Programming by intention has now generated a mixin and two classes that have a clean separation of responsibilities.  Here is the simplest thing that could possibly work to make the feature pass.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># lib/query_parser.rb</span>
<span style="color:#9966CC; font-weight:bold;">module</span> Ruminate
  <span style="color:#9966CC; font-weight:bold;">class</span> QueryParser
    <span style="color:#9966CC; font-weight:bold;">def</span> parse query
      <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># lib/engine.rb</span>
<span style="color:#9966CC; font-weight:bold;">module</span> Ruminate
  <span style="color:#9966CC; font-weight:bold;">class</span> Engine
    <span style="color:#9966CC; font-weight:bold;">def</span> execute query
      <span style="color:#996600;">&quot;Google&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Obviously this isn&#8217;t the final code, but it gives us the minimal implementation to pass the feature.  Now I can turn to Test::Unit and shoulda to flesh out tests and implementations to make it work in a more useful manner.</p>
<p>What I really wanted to show here is how to get a TDD project started.  I know that I&#8217;ve struggled with this in the past.  What to test first can be a big decision, one that can create a type of code writers block. When this moment happened where everything just came together and I was able to generate a mixin and two orthagonal classes with a simple feature, I wanted to write it up.</p>
<h3>The Code</h3>
<p>The full code for this example can be found <a href="http://github.com/rubyyot/ruminate/tree/simplest-thing-that-could-possibly-work">on github with the tag simplest-thing-that-could-possibly-work</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/06/getting-a-project-off-the-ground-with-tdd-and-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making your Rails controllers respond</title>
		<link>http://blog.rubyyot.com/2009/05/making-your-rails-controllers-respond/</link>
		<comments>http://blog.rubyyot.com/2009/05/making-your-rails-controllers-respond/#comments</comments>
		<pubDate>Fri, 08 May 2009 14:00:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=341</guid>
		<description><![CDATA[I was looking at Google Analytics today and found that the following searhes often end up here:

webrat no action responded to /. actions: index

and

&#34;no action responded to&#34; webrat

It&#8217;s good to see that people are trying out webrat, presumably with cucumber to test their apps.
The problem here is most likely that you need to add a [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at Google Analytics today and found that the following searhes often end up here:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">webrat no action responded to <span style="color: #000000; font-weight: bold;">/</span>. actions: index</pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #ff0000;">&quot;no action responded to&quot;</span> webrat</pre></div></div>

<p>It&#8217;s good to see that people are trying out webrat, presumably with cucumber to test their apps.</p>
<p>The problem here is most likely that you need to add a method to your controller to handle the incoming request.  So if you are getting the message</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">no action responded to new</pre></div></div>

<p>you would want to go to the controller that you are testing and add something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> new
    <span style="color:#008000; font-style:italic;">#TODO make new do something</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Don&#8217;t forget to add a view such as app/views/example/new.html.erb that corresponds to the action you just added to your controller.</p>
<p>Also, <a href="http://blog.rubyyot.com/2009/05/gtd-on-rails-with-annotations/">learn to find the TODO annotation again with rake.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/05/making-your-rails-controllers-respond/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cucumber lost the letter a on windows</title>
		<link>http://blog.rubyyot.com/2009/05/cucumber-lost-the-letter-a-on-windows/</link>
		<comments>http://blog.rubyyot.com/2009/05/cucumber-lost-the-letter-a-on-windows/#comments</comments>
		<pubDate>Tue, 05 May 2009 20:34:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[letter a]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/05/cucumber-lost-the-letter-a-on-windows/</guid>
		<description><![CDATA[Find that the letter &#8216;a&#8217; is missing from your output from cucumber in windows?  Try adding the line
$KCODE=''
to your features/support/env.rb file.
It worked for me.
]]></description>
			<content:encoded><![CDATA[<p>Find that the letter &#8216;a&#8217; is missing from your output from cucumber in windows?  Try adding the line</p>
<pre>$KCODE=''</pre>
<p>to your features/support/env.rb file.</p>
<p>It worked for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/05/cucumber-lost-the-letter-a-on-windows/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Listing of cucumber&#039;s out-of-the-box webrat steps</title>
		<link>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/</link>
		<comments>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 18:09:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cucumber]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/</guid>
		<description><![CDATA[Commonly used webrat steps found in cucumber
(replace words in [brackets] with the approprate word.)
Given

Given I am on [page_name]

When

When I go to [page_name]
When I press "[button]"
When I follow "[link]"
When I fill in "[field]" with "[value]"
When I select "[value]" from "[field]"
When I select "[time]" as the date and time				#datetime_select
When I select "[datetime]" as the "[datetime_label]" date and [...]]]></description>
			<content:encoded><![CDATA[<p>Commonly used <a href="http://github.com/brynary/webrat">webrat</a> steps found in <a href="http://github.com/brynary/cucumber">cucumber</a></p>
<p>(replace words in [brackets] with the approprate word.)</p>
<h3>Given</h3>
<pre>
Given I am on [page_name]
</pre>
<h3>When</h3>
<pre>
When I go to [page_name]
When I press "[button]"
When I follow "[link]"
When I fill in "[field]" with "[value]"
When I select "[value]" from "[field]"
When I select "[time]" as the date and time				#datetime_select
When I select "[datetime]" as the "[datetime_label]" date and time	#specific datetime_select
When I select "[time]" as the time			#time select
When I select "[time]" as the "[time_label]" time	#specific time select
When I select "[date]" as the date			#date_select
When I select "[date]" as the "[date_label]" date	#specific date_select
When I check "[field]"
When I uncheck "[field]"
When I choose "[field]"
When I attach the file at "[path]" to "[field]"
</pre>
<h3>Then</h3>
<pre>
Then I should see "[text]"
Then I should not see "[text]"
Then the "[field]" field should contain "[value]"
Then the "[field]" field should not contain "[value]"
Then the "[label]" checkbox should be checked
Then I should be on [page_name]
</pre>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=d61ef58d-41df-8e0a-a2e5-73f18ab347ca" /></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chores: a test driven website &#8211; part 6 (the son of)</title>
		<link>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-6/</link>
		<comments>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-6/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 06:07:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chores]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=192</guid>
		<description><![CDATA[This is part of the Chores series of posts
Last time we found the warm fuzzy feeling of green tests and a completed feature.   Unfortunately, while that is a great feeling, our website is far from complete.  We can however begin to leverage what we have learned so far to get this project moving.  I write [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part of <a href="http://blog.rubyyot.com/chores-a-test-driven-website/" target="_blank">the Chores series of posts</a></em></p>
<p>Last time we found the warm fuzzy feeling of green tests and a completed feature.   Unfortunately, while that is a great feeling, our website is far from complete.  We can however begin to leverage what we have learned so far to get this project moving.  I write up my next feature for cucumber and save it in the features directory as define_children.feature. </p>
<pre>Story:  Define child
As a parent
I want to define my child(ren)
So that I can assign them chores

Scenario: Defining a child
Given I am on the homepage
When I follow "Add Child"
And I fill in "child[nickname]" with "Bobby"
And I fill in "child[open_identifier]" with "bobby.example.com"
And I press "Add"
Then I should see "Child added."
And I should see "Bobby"

Scenario: Defining a second child
Given I am on the homepage
When I follow "Add Child"
And I fill in "child[nickname]" with "Bobby"
And I fill in "child[open_identifier]" with "bobby.example.com"
And I press "Add"
And I follow "Add another Child"
And I fill in "child[nickname]" with "Suzy"
And I fill in "child[open_identifier]" with "suzy.example.com"
And I press "Add"
Then I should see "Child added."
And I should see "Bobby"
And I should see "Suzy" </pre>
<p>Here are a few things that you can pick out of this feature.</p>
<ul>
<li>It infers  that there is some sort of identity, probably with some sort of authentication at a future point.</li>
<li>Identities will likely have roles of parent and child.</li>
<li>The fact that the child is associated with an openID confirms that there will be authentication at some point.</li>
<li>Identites have either a one-to-many or a many-to-many relationship.</li>
</ul>
<p>I think (at this point) that I&#8217;m going to leave the actual authentication out of the scope of the feature.  However it looks like there will be an Identity and some sort of relationship model in our near future.  Notice also that I took advantage of some of <a title="Built in webrat steps" href="http://blog.rubyyot.com/2009/01/if-you-buy-cucumber-and-webrat-now-you-will-also-get/" target="_blank">webrat&#8217;s built in step defintions</a>.  I considered making a custom step to combine the entering of nickname, openId and pressing add, but I left it with the defaults for now.</p>
<p>Before we go ahead and create the models, let&#8217;s follow our feature and see where it leads us.  Cucumber&#8217;s output looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ cucumber features
Story:  Define child  <span style="color:#008000; font-style:italic;"># features/define_children.feature</span>
As a parent
I want to define my child<span style="color:#006600; font-weight:bold;">&#40;</span>ren<span style="color:#006600; font-weight:bold;">&#41;</span>
So that I can assign them chores
  Scenario: Defining a child      <span style="color:#008000; font-style:italic;"># features/define_children.feature:6</span>
    Given I am on the homepage   <span style="color:#008000; font-style:italic;"># features/step_definitions/chores_steps.rb:1</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I follow <span style="color:#996600;">&quot;Add Child&quot;</span>      <span style="color:#008000; font-style:italic;"># features/step_definitions/webrat_steps.rb:8</span>
      Could <span style="color:#9966CC; font-weight:bold;">not</span> find link with text <span style="color:#996600;">&quot;Add Child&quot;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">RuntimeError</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      c:<span style="color:#006600; font-weight:bold;">/</span>Ruby<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>ruby<span style="color:#006600; font-weight:bold;">/</span>gems<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">1.8</span><span style="color:#006600; font-weight:bold;">/</span>gems<span style="color:#006600; font-weight:bold;">/</span>webrat<span style="color:#006600; font-weight:bold;">-</span>0.3.4<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>webrat<span style="color:#006600; font-weight:bold;">/</span>core<span style="color:#006600; font-weight:bold;">/</span>flunk.<span style="color:#9900CC;">rb</span>:<span style="color:#006666;">4</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">'flunk'</span></pre></div></div>

<p>So we will need to modify the homepage to have a link to add child and to do that we will need to have a url to go to.   That means we need a controller.  Since the link we are making is to add a child let&#8217;s call it the Children Controller. </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate controller Children index new create
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>children
      exists  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>children_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>children_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>children_helper.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>children<span style="color: #000000; font-weight: bold;">/</span>index.html.erb
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>children<span style="color: #000000; font-weight: bold;">/</span>new.html.erb
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>children<span style="color: #000000; font-weight: bold;">/</span>create.html.erb</pre></div></div>

<p>and update ./config/routes.rb to read</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing::Routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span>
  map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:chores</span>
  map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:children</span>
  map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'home'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>and finally update our homepage view (./app/views/home/index.html.erb) to read</p>
<p>views</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Add Chore&quot;</span>, new_chore_path <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Add Child&quot;</span>, new_child_path <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p lang="bash">Let&#8217;s check back with Cucumber and see how we did.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define child  <span style="color: #666666; font-style: italic;"># features/define_children.feature</span>
As a parent
I want to define my child<span style="color: #7a0874; font-weight: bold;">&#40;</span>ren<span style="color: #7a0874; font-weight: bold;">&#41;</span>
So that I can assign them chores
  Scenario: Defining a child      <span style="color: #666666; font-style: italic;"># features/define_children.feature:6</span>
    Given I am on the homepage      <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
    When I follow <span style="color: #ff0000;">&quot;Add Child&quot;</span>      <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:8</span>
    And I fill <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;child[nickname]&quot;</span> with <span style="color: #ff0000;">&quot;Bobby&quot;</span>      <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:12</span>
      Could not <span style="color: #c20cb9; font-weight: bold;">find</span> field labeled <span style="color: #ff0000;">&quot;child[nickname]&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>RuntimeError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      c:<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>webrat-0.3.4<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>webrat<span style="color: #000000; font-weight: bold;">/</span>core<span style="color: #000000; font-weight: bold;">/</span>flunk.rb:<span style="color: #000000;">4</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'flunk'</span></pre></div></div>

<p lang="bash">Not bad at all the step passed and it is now looking for the form on the new view.   Let&#8217;s make it by editing /app/views/children/new.html.erb to read:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@child<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;p&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:nickname</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:nickname</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
&nbsp;
  &lt;p&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:open_identifier</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:open_identifier</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">&quot;Add&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Let&#8217;s also remove ./app/views/children/create.html.erb file while we are at it, since we won&#8217;t need a view for this method.</p>
<p>Hmmm. hold on for a second. We are referencing an instance of @child that doesn&#8217;t exist. That&#8217;s definately going to fail. We need to add a model to define relationships between identities not to mention the identities themselves.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate model Identity identifier:string
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>identity.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>identity_test.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>identities.yml
      exists  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090124055031</span>_create_identities.rb</pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate model Child parent_id:integer child_id:integer
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>child.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>child_test.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>children.yml
      exists  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090124055548</span>_create_children.rb</pre></div></div>

<p>When we return it will be time to edit the migrations and run them and then dive back into Test::Unit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>If you buy Cucumber and Webrat now, you will also get&#8230;</title>
		<link>http://blog.rubyyot.com/2009/01/if-you-buy-cucumber-and-webrat-now-you-will-also-get/</link>
		<comments>http://blog.rubyyot.com/2009/01/if-you-buy-cucumber-and-webrat-now-you-will-also-get/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 05:52:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=167</guid>
		<description><![CDATA[When you install Cucumber to your Rails project you get a number of  built in steps out of the box without any additonal effort.  These steps will do a number of common tasks.   Using them is a simple matter of knowing the correct wording.  If you want to see these steps for yourself, open ./features/step_definitions/webrat_steps.rb [...]]]></description>
			<content:encoded><![CDATA[<p>When you install Cucumber to your Rails project you get a number of  built in steps out of the box without any additonal effort.  These steps will do a number of common tasks.   Using them is a simple matter of knowing the correct wording.  If you want to see these steps for yourself, open ./features/step_definitions/webrat_steps.rb in your project after you have installed cucumber in your project.</p>
<p>Here are are a number of useful steps that are included with webrat:</p>
<ul>
<li><strong>Submitting a form with a button</strong> &#8211; Let&#8217;s say you have a feature to collect email addresses and you have gotten to the step where the user clicks the button marked &#8220;I love Spam&#8221; to entrust you with their email address.   To perform the clicking of the spammy button in your cucumber feature simply write the step.</li>
</ul>
<p style="TEXT-ALIGN: center"><em>When I press &#8220;I love Spam&#8221;</em></p>
<ul>
<li>
<div style="TEXT-ALIGN: left"> <strong>Clicking a link</strong> &#8211; Have a feature that includes clicking a link labeled &#8220;Log in&#8221; that logs you in to the website?  To click the link in your test simply use the following.</div>
</li>
</ul>
<p style="TEXT-ALIGN: center"><em>When I follow &#8220;Log in&#8221;</em></p>
<ul>
<li><strong>Filling in a field in a form</strong> &#8211; Let&#8217;s say you are writing the website where people can go to register their mouse.  You have a new action on your form controller and the view for new allows the user to fill in the serial number of their mouse to be saved via your Mouse model.   The html generated by this view would name the serial number field something like &#8220;mouse[serial_number]&#8220;.   To write a feature where you enter a serial number of &#8220;I10v3M1c3&#8243; and click a button named &#8220;Submit&#8221;, you would simply use the following pre-built webrat steps in your feature.</li>
</ul>
<p style="TEXT-ALIGN: center"><em>When I fill in &#8220;mouse[serial_number]&#8221; with &#8220;I1ov3M1c3&#8243;</em></p>
<p style="TEXT-ALIGN: center"><em>And I press &#8220;Submit&#8221;</em></p>
<ul>
<li><strong>Verifying that text is displayed</strong> &#8211; So you want ensure that a message is  sent to the screen that says &#8220;Hey smart guy, you entered your gender as a numeric value!&#8221;?  Use the following step to make sure that text is being displayed in the response.</li>
</ul>
<p style="TEXT-ALIGN: center"><em>Then I should see &#8220;Hey smart guy, you entered your gender as a numeric value!&#8221;</em></p>
<p style="TEXT-ALIGN: left">These are just a few of the pre-built steps available to you that you can use without any step writing at all.  Check them out. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/if-you-buy-cucumber-and-webrat-now-you-will-also-get/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chores:  A test driven website, part 2</title>
		<link>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/</link>
		<comments>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 13:25:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chores]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=53</guid>
		<description><![CDATA[This is part of the Chores series of posts
In which I continue to build the chores website and demonstating how simple it is to use a test first methodology. To follow along, please see my previous post.
Doh!  I forgot to commit!
When I left off, I had come to a natural stopping point.  A [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part of <a href="http://blog.rubyyot.com/chores-a-test-driven-website/">the Chores series of posts</a></em></p>
<p>In which I continue to build the chores website and demonstating how simple it is to use a test first methodology. To follow along, please <a href="http://blog.rubyyot.com/2009/01/chores-a-test-driven-website/" rel="me">see my previous post.</a></p>
<h2>Doh!  I forgot to commit!</h2>
<p>When I left off, I had come to a natural stopping point.  A place where I was shifting focus from features to unit testing.  I like to make my commits when my tests are all passing, however if I&#8217;m implementing a new feature, I don&#8217;t apply this hueristic since completing a feature will span multiple units of work. So let&#8217;s commit this.  First let&#8217;s see where I am:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;"># Untracked files:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#       features/</span>
<span style="color: #666666; font-style: italic;">#       lib/</span>
<span style="color: #666666; font-style: italic;">#       script/cucumber</span>
nothing added to commit but untracked files present <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> to track<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ok, git sees that I&#8217;ve added cucumber to my rails app and that I have added a feature.  Let&#8217;s add these changes to our commit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git add .</pre></div></div>

<p>and commit them</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;added feature to create chores&quot;</span></pre></div></div>

<p>and finally push a copy out to the repository I set up on my shared host.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git push origin master</pre></div></div>

<p>there all set.</p>
<h2>Routing to home</h2>
<p>At this point I&#8217;m a little confused as to how to proceed test first.  We have a failing feature.  When I have a failing feature I like to start by making a test to simulate the same error.  However in this case, that is difficult at best, and the failing feature has already told me what I need to do, which is create a home_controller</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate controller Home
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home
      exists  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>home_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>home_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>home_helper.rb</pre></div></div>

<p>.. and map a route to it.  To do that I open up my ./config/routes.rb file and add the following route.  I like to get rid of the legacy routes so I&#8217;ll replace the entire text of the file with the following</p>
<p>[sourcecode language="ruby"]<br />
ActionController::Routing::Routes.draw do |map|<br />
  map.root :controller => &#8216;home&#8217;<br />
end
</pre>
<h2>So what are these controllers and routes?</h2>
<p>If you are new to Rails, you are probably wondering what we just did.  The controller is the C in the MVC pattern that Rails uses.  It's role is to handle web serving of the application.  It's kind of like an office assistant for your application.  It be able to handle frequent requests and delegate them to the proper subject matter expert.  When a request comes in for a list of Widgets, it will go to the Widget model and ask it for a list of widgets and then pass that off to the user interface (view) to display in the browser.  When the user interface passes it a bag of information and asks it to save the information, the controller will create an instance of the appropriate model from the bag of information and then tell the model it should save the information.</p>
<p>Controllers really shouldn't become too involved in the details, but should delegate well to the objects that know what they are doing.  Rails have a nice script to generate controllers, which we used above.  In this case we generated a home controller which we will use to handle requests for the application's home page or root.</p>
<p>The second thing we did is define a route.  Routes are related to controllers, in that they show the framework how to translate a request such as http://www.exmaple.com/sprocket/new into a method call on a controller.  In the case of the above url, it would call the method new on the sprocket controller.  You can find your routes in config/routes.rb and view all of your current routes with the rake task</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake routes</pre></div></div>

<h2>On with the show!</h2>
<p>Now let's go back to cucumber and see where we are.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore       <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      No action responded to index. Actions:  <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionController::UnknownAction<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ok, our route is now wired up nicely to the controller, but the home controller does not respond to index.  Lets add this to the controller</p>
<p>[sourcecode language="ruby"]<br />
class HomeController < ApplicationController<br />
  def index</p>
<p>  end<br />
end
</pre>
<p>and try cucumber again</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore     <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      Missing template home<span style="color: #000000; font-weight: bold;">/</span>index.erb <span style="color: #000000; font-weight: bold;">in</span> view path c:<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>chores<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views: <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::MissingTemplate<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ah ha!  We are making progress.  Our request has passed through the controller and is now looking for a view to render. One thing that I would like to point out is that doing the development in this way really lays out how the pieces of Rails all fit together.  Something that we wouldn't have seen if we had chosen to generate a scaffold or we built it piecemeal without the tests metering our pace.</p>
<h2></h2>
<h2>Views</h2>
<p>Views are what end up being displayed in the web browser, they are a sort of template.  By default, erb will process the template in the context of your request and output the dynamic content.  Pretty cool stuff, and it gives you great control over your output.</p>
<p>Well what are we waiting for, let's make a view.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">touch</span> app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>index.html.erb</pre></div></div>

<p>In windows you can use your IDE or folder browser to create the file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
Story:  Define chores
As a parent
I want to define chores
So that I can assign them to my children
&nbsp;
  Scenario: Creating a chore                          <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage                        <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:6</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>                         <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:18</span>
      Could not <span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #c20cb9; font-weight: bold;">link</span> with text or title or <span style="color: #c20cb9; font-weight: bold;">id</span> <span style="color: #ff0000;">&quot;Add Chore&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Webrat::NotFoundError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">eval</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:<span style="color: #000000;">2</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'/^I follow &quot;([^&quot;]*)&quot;$/'</span>
      features<span style="color: #000000; font-weight: bold;">/</span>define_chores.feature:<span style="color: #000000;">8</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'When I follow &quot;Add Chore&quot;'</span>
    And I fill <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;chore[name]&quot;</span> with <span style="color: #ff0000;">&quot;My first chore&quot;</span> <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:22</span>
    And I press <span style="color: #ff0000;">&quot;Add&quot;</span>                                 <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:14</span>
    Then I should see <span style="color: #ff0000;">&quot;Chore added.&quot;</span>                  <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:93</span>
    And I should see <span style="color: #ff0000;">&quot;My first chore&quot;</span>                 <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:93</span>
&nbsp;
<span style="color: #000000;">1</span> scenario
<span style="color: #000000;">1</span> failed step
<span style="color: #000000;">4</span> skipped steps
<span style="color: #000000;">1</span> passed step
rake aborted<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>Hey look! Our first step has passed!  Let's give ourselves a pat on the back.  We have a website with a dynamic (albeit blank) homepage, that is tested.</p>
<h2>Not all quotes are equal</h2>
<p>I had an issue with my feature where the double quotes in my feature were translated automatically to open and closed style quotes.  This was causing my steps not to match.  If you find that you have a bunch of steps that are undefined at this point, that may be the issue.</p>
<h2>Catch the passing step fever</h2>
<p>The next step is one that is generated by webrat.  It is looking for a link to follow called "Add Chore".  The problem is that we didn't actually add the link, or anything else to the view. So let's update the view to read</p>
<p>[sourcecode language="ruby"]<br />
<%= link_to "Add Chore", chore_path %>
</pre>
<p>and fire up cucumber</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore      <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      undefined <span style="color: #7a0874; font-weight: bold;">local</span> variable or method <span style="color: #ff0000;">'chore_path'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #666666; font-style: italic;">#&lt;actionView::Base:0x4baf67c&gt; (ActionView::TemplateError)</span>
      On line <span style="color: #666666; font-style: italic;">#1 of app/views/home/index.html.erb</span>
&nbsp;
      <span style="color: #000000;">1</span>: <span style="color: #000000; font-weight: bold;">&lt;%</span>= link_to <span style="color: #ff0000;">&quot;Add Chore&quot;</span>, chore_path <span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
      app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>index.html.erb:<span style="color: #000000;">1</span></pre></div></div>

<p>ok, we need to define resource for this, let's add a route and controller.</p>
<p>[sourcecode language="ruby"]<br />
ActionController::Routing::Routes.draw do |map|<br />
  map.resources :chores<br />
  map.root :controller => 'home'<br />
end
</pre>
<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate controller Chores
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>chores
      exists  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>chores_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>chores_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>chores_helper.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      chore_url failed to generate from <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;show&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;chores&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
 - you may have ambiguous routes, or you may need to supply additional parameter
s <span style="color: #000000; font-weight: bold;">for</span> this route.  content_url has the following required parameters: <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;chores&quot;</span>,
 :<span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> - are they all satisfied? <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::TemplateError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      On line <span style="color: #666666; font-style: italic;">#1 of app/views/home/index.html.erb</span>
&nbsp;
      <span style="color: #000000;">1</span>: <span style="color: #000000; font-weight: bold;">&lt;%</span>= link_to <span style="color: #ff0000;">&quot;Add Chore&quot;</span>, chore_path <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>Dang it! still getting an error.  Hmmm.. wait a minute.  chore_path is generating a show action.  That's not what we want to do.  We want a new action to be RESTful or maybe an index action if we don't see REST in the future for this app. A quick consultation with the domain expert (me) says that there is no valid reason not follow the RESTful guidelines at this point so let's fix the home/index view to read.</p>
<p>[sourcecode language="ruby"]<br />
<%= link_to "Add Chore", new_chore_path %>
</pre>
<p>cucumber says...</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore   <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>   <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:8</span>
      No action responded to new. Actions:  <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionController::UnknownAction<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Great!  That fixed it.  Now we need to make sure there is a new action on the chores controller.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ChoresController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> new
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>      <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:8</span>
      Missing template chores<span style="color: #000000; font-weight: bold;">/</span>new.erb <span style="color: #000000; font-weight: bold;">in</span> view path c:<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>chores<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views: <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::MissingTemplate<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>cucumber likes it!  But we still have an error.  Let's create ./app/views/chores/new.html.erb as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@chore<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
  &lt;p&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
&nbsp;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">&quot;Add&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Hmmm.. wait we are getting ahead of ourselves. We need a model to be able to pass it to our view.  We will have to generate that next.</p>
<p>Well we didn't get to Test::Unit this time around, but with a model in sight it's sure to be right around the corner.  Until next time..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Chores:  A test driven website</title>
		<link>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website/</link>
		<comments>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 05:00:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Castle]]></category>
		<category><![CDATA[Chores]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=41</guid>
		<description><![CDATA[I admit it, I don't always write my tests first, and at other times I don't write my tests at all. There I said it. However, I have found that writing tests first has accelerated the speed at which I learn and it has improved the quality of my work.]]></description>
			<content:encoded><![CDATA[<p><em>This is part of <a href="http://blog.rubyyot.com/chores-a-test-driven-website/">the Chores series of posts</a></em></p>
<p>I admit it, I don&#8217;t always write my tests first, and at other times I don&#8217;t write my tests at all. There I said it. However, I have found that writing tests first has accelerated the speed at which I learn and it has improved the quality of my work.</p>
<p>There is a general feeling that people who use TDD see themselves as better than those who don&#8217;t use it.  I don&#8217;t think that this is the case.  I think that this happens because once you start working in these styles, it&#8217;s strange to work without them.  It&#8217;s not that you can&#8217;t or won&#8217;t do it, but it feels like you are working with a reduced toolset when you do.</p>
<p>I&#8217;m no expert at test driven development or similar styles, but the more I use them, the harder it is to imagine not being able to design and shape my objects with automated tests.  I wouldn&#8217;t want to figure out how related objects fit together without the documentation that automated testing provides.</p>
<p>The term test driven fools people into thinking that it&#8217;s all about testing, but it&#8217;s not.  It&#8217;s about creating functional designs with reduced dependencies.  It&#8217;s also about being able to maintain your code.  It&#8217;s about self improvement.</p>
<p>The point of learning to work in these styles is not to be better than those that don&#8217;t.  Instead, the point is to make the code you wrote today better than the code you wrote a week ago, or a month ago. It is also so that when you or someone else looks at the code you wrote today, they will find it to be:</p>
<ul>
<li>working</li>
<li>documented</li>
<li>flexable</li>
<li>extendable</li>
</ul>
<p>There are many articles on the benefits of working in this style, and my point is not to repeat them.  In fact my purpose is to prove them correct, or at least to show that it is not difficult to do and just takes a little discipline.  The same discipline that I lack at times, but I&#8217;m getting better.</p>
<h3>The Project</h3>
<p>I am the father of 4 kids, and they are wonderful children who make messes and generally don&#8217;t clean up after themselves unless told to do so (and sometimes not even then).   My general idea of a website is to built a Rails app that a family can go and if they are parents, keep track of what their kids do or don&#8217;t do.  If they are kids, they can document what they have done and perhaps see much they have earned for the week in allowance.  I have tried doing allowances before, but the problem is that my kids have to be told to do what they are supposed to be doing quite often to make sure they are doing it.   I don&#8217;t want to do this.   I want to provide immediate feedback for them on what they are earning, and I am hoping that this will give them the motivation they need to keep going.  I also want to help them to develop the habits that will continue with or without the draw of rewards.  It&#8217;s a moderately involved project,</p>
<h3>Test or Die</h3>
<p>Because <a title="Test Awareness Month" href="http://www.railstips.org/2009/1/6/test-or-die" target="_blank">January is Test Awareness Month</a> I have decided to document bulding (at least beginning to build) this site on my blog using Cucumber and Test::Unit to drive it.   I am developing currently on a Windows machine, though this may change as the project goes on as my other machines are running Ubuntu.  So without further ado&#8230;</p>
<p><em>Note: (May 11, 2009 &#8211; I originally created this with Rails v2.2.2.  I&#8217;m currently running back through to check compatability with Rails v2.3.2)</em></p>
<h3>Start!</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ rails chores
      create
      create  app<span style="color:#006600; font-weight:bold;">/</span>controllers
      create  app<span style="color:#006600; font-weight:bold;">/</span>helpers
      .....
      <span style="color:#9900CC;">create</span>  log<span style="color:#006600; font-weight:bold;">/</span>development.<span style="color:#9900CC;">log</span>
      create  log<span style="color:#006600; font-weight:bold;">/</span>test.<span style="color:#9900CC;">log</span></pre></div></div>

<p>I have my rails app.  The first thing I want to do is get this into source control.  In my case git.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ cd chores</pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ git init</pre></div></div>

<p>now I don&#8217;t want to store everything in source control.  To to make git ignore files and or paths I create a .gitignore file in the chores directory and it looks like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">tmp<span style="color:#006600; font-weight:bold;">*</span>
log<span style="color:#006600; font-weight:bold;">*</span>
<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span>~<span style="color:#008000; font-style:italic;">#]</span></pre></div></div>

<p>what this does is it ignores the tmp and log directories and it also ignores any backup files which contain ~ or #.</p>
<p>Now I can check the status to make sure that the .gitignore file is working.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ git status
<span style="color:#008000; font-style:italic;"># On branch master</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Initial commit</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Untracked files:</span>
<span style="color:#008000; font-style:italic;">#   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;">#       .gitignore</span>
<span style="color:#008000; font-style:italic;">#       README</span>
<span style="color:#008000; font-style:italic;">#       Rakefile</span>
<span style="color:#008000; font-style:italic;">#       app/</span>
<span style="color:#008000; font-style:italic;">#       config/</span>
<span style="color:#008000; font-style:italic;">#       doc/</span>
<span style="color:#008000; font-style:italic;">#       public/</span>
<span style="color:#008000; font-style:italic;">#       script/</span>
<span style="color:#008000; font-style:italic;">#       test/</span>
nothing added to commit but untracked files present <span style="color:#006600; font-weight:bold;">&#40;</span>use <span style="color:#996600;">&quot;git add&quot;</span> to track<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Followed by</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ git add .
&nbsp;
$ git commit <span style="color:#006600; font-weight:bold;">-</span>am <span style="color:#996600;">&quot;initial commit&quot;</span></pre></div></div>

<p>Which adds my site to git&#8217;s index and commits my first commit.  Now I&#8217;m going to backup my git repository to my shared host.  A <a title="Git's your shared host on" href="http://railstips.org/2008/11/24/gitn-your-shared-host-on" target="_blank">good explanation of this can be found here</a>.</p>
<p>Now I already have <a title="Cucumber readme" href="http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails" target="_blank">cucumber, webrat and rspec installed as gems.</a>  In order to drive my development with cucumber features I need to set up my app to use cucumber.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ ruby script<span style="color:#006600; font-weight:bold;">/</span>generate cucumber
      create  features<span style="color:#006600; font-weight:bold;">/</span>step_definitions
      create  features<span style="color:#006600; font-weight:bold;">/</span>step_definitions<span style="color:#006600; font-weight:bold;">/</span>webrat_steps.<span style="color:#9900CC;">rb</span>
      create  features<span style="color:#006600; font-weight:bold;">/</span>support
      create  features<span style="color:#006600; font-weight:bold;">/</span>support<span style="color:#006600; font-weight:bold;">/</span>env.<span style="color:#9900CC;">rb</span>
      create  features<span style="color:#006600; font-weight:bold;">/</span>support<span style="color:#006600; font-weight:bold;">/</span>paths.<span style="color:#9900CC;">rb</span>
      exists  lib<span style="color:#006600; font-weight:bold;">/</span>tasks
      create  lib<span style="color:#006600; font-weight:bold;">/</span>tasks<span style="color:#006600; font-weight:bold;">/</span>cucumber.<span style="color:#9900CC;">rake</span>
      create  script<span style="color:#006600; font-weight:bold;">/</span>cucumber</pre></div></div>

<p>That does the trick.</p>
<h3>Gotchas</h3>
<p>I&#8217;ve found a couple gotchas at this point when working in Windows.  The first is that <a title="Where did 'a' go?" href="http://blog.rubyyot.com/2009/05/cucumber-lost-the-letter-a-on-windows/" target="_blank"> cucumber doesn&#8217;t display the letter &#8216;a&#8217; in the output</a> if you don&#8217;t modify ./features/support/env.rb with the following line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#ff6633; font-weight:bold;">$KCODE</span>=<span style="color:#996600;">''</span></pre></td></tr></table></div>

<p>also you will want to make sure you are using <a title="Sqlite3 gem for windows" href="http://blog.rubyyot.com/2009/05/sqlite3-ruby-gem-not-working-on-windows/" target="_blank"> a version of the sqlite gem that supports windows</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> sqlite3-ruby <span style="color: #660033;">-v</span>=1.2.3</pre></div></div>

<h3>What are your features?</h3>
<p>Cucumber Features are a nice way to be able to document what you want your site to do and verify that it does it.   Probably the easiest way do show this is to do it.  I like to make features that aren&#8217;t too broad or two specific.  I will start with one that is core functionality and save it in the ./features directory as define_chores.feature</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Story:  Define chores
As a parent
I want to define chores
So that I can assign them to my children
&nbsp;
Scenario: Creating a chore
Given I am on the homepage
<span style="color:#9966CC; font-weight:bold;">When</span> I follow “Add Chore”
<span style="color:#9966CC; font-weight:bold;">And</span> I fill <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">&quot;chore[name]&quot;</span> with “My first chore”
<span style="color:#9966CC; font-weight:bold;">And</span> I press <span style="color:#996600;">&quot;Add&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> I should see “Chore added.”
<span style="color:#9966CC; font-weight:bold;">And</span> I should see “My first chore”</pre></div></div>

<p>Now we have written our first feature. It is a pretty simple one, but as you can see it describes our intent in readable English. Now let&#8217;s fire up cucumber and see what we get.</p>
<p><em><strong>Update:</strong> The following issue was fixed when I tried it in Rails 2.3.2 and cucumber 0.3.1.</em></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ cucumber features
c:<span style="color:#006600; font-weight:bold;">/</span>Ruby<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>ruby<span style="color:#006600; font-weight:bold;">/</span>site_ruby<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">1.8</span><span style="color:#006600; font-weight:bold;">/</span>rubygems<span style="color:#006600; font-weight:bold;">/</span>custom_require.<span style="color:#9900CC;">rb</span>:<span style="color:#006666;">31</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`gem_original_require': no such file to load -- webrat/rspec-rails (MissingSourceFile)</span></pre></div></div>

<p>Hmmm..  what happened here.   Cucumber uses the ./features/support/env.rb file for configuration let&#8217;s look there.  Sure enough there is a require statement for &#8216;webrat/rspec-rails&#8217;.  <a title="Google" href="http://www.google.com/search?sourceid=navclient&#038;ie=UTF-8&#038;rlz=1T4GGLL_enUS308US308&#038;q=webrat%2frspec-rails+cucumber+error" target="_blank">Let&#8217;s google it. </a>  Looks like the offending require is to add some webrat matchers to rspec.   I&#8217;m just going to comment it out for now and try again.</p>
<p><em><strong>Update:</strong> Using the features rake task (rake features from the command line) at this point in Rails 2.3.2 and cucumber 0.3.1 caused the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">rake aborted!
no such file to <span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#006600; font-weight:bold;">--</span> <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>rubyyot<span style="color:#006600; font-weight:bold;">/</span>working<span style="color:#006600; font-weight:bold;">/</span>chores<span style="color:#006600; font-weight:bold;">/</span>db<span style="color:#006600; font-weight:bold;">/</span>schema.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>This is because we have not yet defined any database tables.  To fix this we simply have to create an empty file in the correct location.  In Windows you can navigate to the folder and create a new file.  In Linux you can type from your rails root:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">touch db<span style="color:#006600; font-weight:bold;">/</span>schema.<span style="color:#9900CC;">rb</span></pre></div></div>

<p></em></p>
<p>This time I get:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ rake features
Story:  Define chores
As a parent
I want to define chores
So that I can assign them to my children
&nbsp;
  Scenario: Creating a chore                          <span style="color:#008000; font-style:italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage                        <span style="color:#008000; font-style:italic;"># features/step_definitions/webrat_steps.rb:6</span>
      No route matches <span style="color:#996600;">&quot;/&quot;</span> with <span style="color:#006600; font-weight:bold;">&#123;</span>:method<span style="color:#006600; font-weight:bold;">=&gt;</span>:get<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActionController::RoutingError</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">eval</span><span style="color:#006600; font-weight:bold;">&#41;</span>:<span style="color:#006666;">2</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">'/^I am on (.+)$/'</span>
      features<span style="color:#006600; font-weight:bold;">/</span>define_chores.<span style="color:#9900CC;">feature</span>:<span style="color:#006666;">7</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">'Given I am on the homepage'</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I follow “Add Chore”                         <span style="color:#008000; font-style:italic;"># features/define_chores.feature:8</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I fill <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">&quot;chore[name]&quot;</span> with “My first chore” <span style="color:#008000; font-style:italic;"># features/define_chores.feature:9</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I press <span style="color:#996600;">&quot;Add&quot;</span>                                 <span style="color:#008000; font-style:italic;"># features/step_definitions/webrat_steps.rb:14</span>
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should see “Chore added.”                  <span style="color:#008000; font-style:italic;"># features/define_chores.feature:11</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I should see “My first chore”                 <span style="color:#008000; font-style:italic;"># features/define_chores.feature:12</span>
&nbsp;
<span style="color:#006666;">1</span> scenario
<span style="color:#006666;">1</span> failed step
<span style="color:#006666;">1</span> skipped step
<span style="color:#006666;">4</span> undefined steps
&nbsp;
You can implement step definitions <span style="color:#9966CC; font-weight:bold;">for</span> undefined steps with these snippets:
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I follow “Add Chore”$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I fill <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> with “My first chore”$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>arg1<span style="color:#006600; font-weight:bold;">|</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should see “Chore added\.”$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should see “My first chore”$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
rake aborted!
Command failed with status <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>: <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>ruby1.8 <span style="color:#006600; font-weight:bold;">-</span>I <span style="color:#996600;">&quot;/usr/lib/ruby/gems/1....]
&nbsp;
(See full trace by running task with --trace)</span></pre></div></div>

<h2>So what happened here?</h2>
<p>Cucumber loads up all the features and all of the steps and then uses regular expressions to match the features to the steps.  Then it executes the code associated with each step in order.  Notice that it knew what &#8220;Given I am on the homepage&#8221; meant.  That is because <a title="Built-in webrat steps" target = '_blank' href="http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/">Webrat has already pre-loaded some common rails testing steps for us.</a></p>
<p>So what error are we having here?  It says &#8220;No route matches &#8220;/&#8221; with {:method=>:get}&#8221;.</p>
<h2>What are routes?</h2>
<p>Routes in Rails have some pretty nifty tricks up their sleeves.  Routes map an incoming request to an action on a controller.  They live in config/routes.rb where you will find some good auto-generated documentation on how to configure them.  In this case we need to create a route for our home page.  This is accomplished by adding</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'home'</span></pre></div></div>

<p>somewhere after</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing::Routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span></pre></div></div>

<p>and before</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This tells rails that any requests that come in for the base url should be routed to the HomeController.  Next time we can start working on building this object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
