<?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; Ruby</title>
	<atom:link href="http://blog.rubyyot.com/tag/ruby-programming/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>Ruby Wisdom</title>
		<link>http://blog.rubyyot.com/2010/02/ruby-wisdom/</link>
		<comments>http://blog.rubyyot.com/2010/02/ruby-wisdom/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 04:31:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=715</guid>
		<description><![CDATA[I got this error today testing a Rails 3 app that I&#8217;m working on..

  3&#41; Error:
test_updates_status&#40;QueueWorkerTest&#41;:
NoMethodError: undefined method 'save!' for &#34;g&#34;:String
    /home/rubyyot/working/stuff.longshotlabs.com/lib/stuff/queue_worker.rb:66:in 'block in retrieve_item_info'
    /home/rubyyot/working/stuff.longshotlabs.com/lib/stuff/queue_worker.rb:64:in 'each'
    /home/rubyyot/working/stuff.longshotlabs.com/lib/stuff/queue_worker.rb:64:in 'retrieve_item_info'
    /home/rubyyot/working/stuff.longshotlabs.com/lib/stuff/queue_worker.rb:38:in 'process_unit'
    /home/rubyyot/working/stuff.longshotlabs.com/lib/stuff/queue_worker.rb:14:in 'process_queue'
    /home/rubyyot/working/stuff.longshotlabs.com/test/unit/queue_worker_test.rb:35:in 'test_updates_status'

]]></description>
			<content:encoded><![CDATA[<p>I got this error today testing a Rails 3 app that I&#8217;m working on..</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Error:
test_updates_status<span style="color: #7a0874; font-weight: bold;">&#40;</span>QueueWorkerTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
NoMethodError: undefined method <span style="color: #ff0000;">'save!'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #ff0000;">&quot;g&quot;</span>:String
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>stuff<span style="color: #000000; font-weight: bold;">/</span>queue_worker.rb:<span style="color: #000000;">66</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'block in retrieve_item_info'</span>
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>stuff<span style="color: #000000; font-weight: bold;">/</span>queue_worker.rb:<span style="color: #000000;">64</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'each'</span>
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>stuff<span style="color: #000000; font-weight: bold;">/</span>queue_worker.rb:<span style="color: #000000;">64</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'retrieve_item_info'</span>
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>stuff<span style="color: #000000; font-weight: bold;">/</span>queue_worker.rb:<span style="color: #000000;">38</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'process_unit'</span>
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>stuff<span style="color: #000000; font-weight: bold;">/</span>queue_worker.rb:<span style="color: #000000;">14</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'process_queue'</span>
    <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rubyyot<span style="color: #000000; font-weight: bold;">/</span>working<span style="color: #000000; font-weight: bold;">/</span>stuff.longshotlabs.com<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>queue_worker_test.rb:<span style="color: #000000;">35</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'test_updates_status'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2010/02/ruby-wisdom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#039;t find tokyocabinet native extentions</title>
		<link>http://blog.rubyyot.com/2010/02/cant-find-tokyocabinet-native-extentions/</link>
		<comments>http://blog.rubyyot.com/2010/02/cant-find-tokyocabinet-native-extentions/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 22:27:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[edo]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[tokyo cabinet]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=706</guid>
		<description><![CDATA[I was trying out rufus/edo today after installing Tokyo Cabinet. and I kept getting the following error

/usr/local/lib/site_ruby/1.8/i486-linux/tokyocabinet.so: libtokyocabinet.so.9: cannot open shared object file: No such file or directory - /usr/local/lib/site_ruby/1.8/i486-linux/tokyocabinet.so &#40;LoadError&#41;
        from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from test.rb:1

The solution was to modify the [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying out <a href="http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/edo/README.txt">rufus/edo</a> today after installing Tokyo Cabinet. and I kept getting the following error</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>i486-linux<span style="color: #000000; font-weight: bold;">/</span>tokyocabinet.so: libtokyocabinet.so.9: cannot open shared object <span style="color: #c20cb9; font-weight: bold;">file</span>: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory - <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>i486-linux<span style="color: #000000; font-weight: bold;">/</span>tokyocabinet.so <span style="color: #7a0874; font-weight: bold;">&#40;</span>LoadError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        from <span style="color: #000000; font-weight: bold;">/</span>usr<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><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000; font-weight: bold;">/</span>custom_require.rb:<span style="color: #000000;">31</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>require<span style="color: #ff0000;">'
        from test.rb:1</span></pre></div></div>

<p>The solution was to modify the LD_LIBRARY_PATH to include /usr/local/lib</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#~/.bashrc</span>
&nbsp;
 <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LD_LIBRARY_PATH</span>=<span style="color: #007800;">$LD_LIBRARY_PATH</span>:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2010/02/cant-find-tokyocabinet-native-extentions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating letters like a Prawn star</title>
		<link>http://blog.rubyyot.com/2009/05/generating-letters-like-a-prawn-star/</link>
		<comments>http://blog.rubyyot.com/2009/05/generating-letters-like-a-prawn-star/#comments</comments>
		<pubDate>Mon, 11 May 2009 13:00:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[letter generation]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[prawn]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=373</guid>
		<description><![CDATA[Disclaimer:  No Prawns, the majestic sea creatures,  were harmed in the creation of this post. 
Recently, I had a project to generate letters from information in a file.  The letters were supposed to be both printed out and stored in pdf format.  There are a number of ways that this can be accomplished.  The way [...]]]></description>
			<content:encoded><![CDATA[<p><em>Disclaimer:  No Prawns, the majestic sea creatures,  were harmed in the creation of this post. </em></p>
<p>Recently, I had a project to generate letters from information in a file.  The letters were supposed to be both printed out and stored in pdf format.  There are a number of ways that this can be accomplished.  The way that I expect most people using Windows, would accomplish this would be to harness Word to Access, purchase Adobe Acrobat and MailMerge to their heart&#8217;s content.</p>
<p>I have some issues with this approach, some of them are logical, some are more emotional.  The first two of them is primarily emotional:</p>
<ul>
<li>I hate Access databases</li>
<li>I don&#8217;t like Mail Merge</li>
<li>I wasn&#8217;t sure if I could get Acrobat</li>
<li>Acrobat is not free or open-source</li>
<li>Once the Word document was generated, it would still need to be run through the pdf generation process in Acrobat</li>
</ul>
<p>Additionally, I knew that a Ruby library called Prawn, had recently been written for pdf generation.  I&#8217;ve been trying to find a way to justify doing more Ruby coding, and I had just found it.</p>
<p><a href="http://github.com/rubyyot/whaler/tree/first_post">Whaler </a>is not that project.  That project is going along well, but whaler is not it.  Whaler is a project that I just put together, to show how simple it is to script up letter generation in Ruby with Prawn.</p>
<p>Here is an <a href="http://images.rubyyot.com/3_Jameson_Ortiz_letter.pdf" target='_blank'' >example letter</a>.</p>
<p>Whaler&#8217;s letters are not professional quality,  far from it.  That is not the fault of Prawn, but rather a symptom of my own laziness.  Whaler is merely meant to show how you can easily make professional looking letters with only a little more patience than I have at the moment.   For more details and information about all of the great things that Prawn can do for you, check out the <a href="http://prawn.majesticseacreature.com/">Prawn homepage.</a></p>
<p>Whaler also uses generated (i.e. fake) data, in the real world you would hook it up to ActiveRecord, DataMapper, a csv parser, ruby-dbi or a variety of other options.</p>
<p>You can pull down your own copy via git by entering the following.</p>
<pre>git clone git://github.com/rubyyot/whaler.git</pre>
<p>To make it generate letters use:</p>
<pre>rake letter:generate count=[number_of_letters_to_generate]</pre>
<p>The count parameter is optional, it will generate 3 letters by default.    Whaler will create a directory in your home directory called WhalerOutput and it will fill it with Prawn generated pdfs.</p>
<p>Feel free to mess around with it or use it as a starting point to make a better letter generation utility.  Just don&#8217;t make any junk mail with it.  That&#8217;s what MailMerge is for.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/05/generating-letters-like-a-prawn-star/feed/</wfw:commentRss>
		<slash:comments>2</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>
