<?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>Clayton Lengel-Zigich &#187; Development</title>
	<atom:link href="http://www.claytonlz.com/index.php/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.claytonlz.com</link>
	<description>Ruby on Rails Developer</description>
	<lastBuildDate>Thu, 15 Jul 2010 07:44:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Zero To Tested With Cucumber and Factory Girl</title>
		<link>http://www.claytonlz.com/index.php/2010/03/zero-to-tested-with-cucumber-and-factory-girl/</link>
		<comments>http://www.claytonlz.com/index.php/2010/03/zero-to-tested-with-cucumber-and-factory-girl/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 17:30:35 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=381</guid>
		<description><![CDATA[Get your project from zero to tested leveraging the power of Cucumber and Factory Girl Testing can be a daunting task, especially for developers who are new to Rails. It sounds like a great idea, but where do you start? What do you test? What don&#8217;t you test? For many developers, the hardest part of [...]]]></description>
			<content:encoded><![CDATA[<p></p><h3>Get your project from zero to tested leveraging the power of Cucumber and Factory Girl</h3>

<p>Testing can be a daunting task, especially for developers who are new to Rails. It sounds like a great idea, but where do you start? What do you test? What don&#8217;t you test? For many developers, the hardest part of testing is jumping in and getting your feet wet. Luckily, Cucumber makes getting started with testing easy, you&#8217;ll be testing your code form top to bottom in no time.</p>

<h4>What is Cucumber?</h4>

<p>Cucumber, in simple terms, is a framework for writing human-readable, meaningful tests that allow you to test the full functionality of your Rails project from database access to business logic to what&#8217;s displayed in your views.</p>

<p>From the <a href="http://cukes.info">Cucumber Wiki</a>:</p>

<blockquote><p>Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid &#8211; all rolled into one format.</p></blockquote>

<p>When you write your tests with Cucumber you get full-stack automated tests, documentation and a tool to help you communicate with your product owner.</p>

<h4>Who&#8217;s the Factory Girl?</h4>

<p><a href="http://robots.thoughtbot.com/post/159807023/waiting-for-a-factory-girl">Factory Girl</a> is a fixture replacement for Rails that allows you to create meaningful objects for use in your tests.</p>

<p>From the <a href="http://github.com/thoughtbot/factory_girl">Factory Girl Github Page</a>:</p>

<blockquote><p>factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.</p></blockquote>

<p>When you use Factory Girl in conjunction with Cucumber you can simplify complex test setup and use real objects from the database, not brittle mocks.</p>

<h4>Getting Setup</h4>

<p>Getting your project setup with Cucumber and Factory Girl is pretty straightforward. First, you&#8217;ll need a few gems installed:</p>



<pre lang="">

    sudo gem install cucumber-rails
    sudo gem install webrat
    sudo gem install thoughtbot-factory_girl --source=http://gemcutter.org

</pre>



<p class="note">Note: As of 0.5.0 the Rails specific functionality was extracted from the cucumber gem into the cucumber-rails gem</p>

<p>Cucumber comes pre-packaged with some generators for getting your project ready for testing. From the root of your Rails project, run the generator:</p>



<pre>

    ruby script/generate cucumber --webrat --rspec

</pre>



<p>You&#8217;ll notice that we&#8217;re passing a couple of flags to the generator, <code>--webrat</code> specifies that we want to use webrat as our automated browser and <code>--rspec</code> specifies that we want to use rspec as our test framework. If you don&#8217;t pass these options Cucumber will guess which options you want based on the gems which you have installed.</p>

<p>After running the generator, you will see some output about the files that were created:</p>


<pre>

    create  config/cucumber.yml
    create  config/environments/cucumber.rb
    create  script/cucumber
    create  features/step_definitions
    create  features/step_definitions/web_steps.rb
    create  features/support
    create  features/support/env.rb
    create  features/support/paths.rb
    create  lib/tasks
    create  lib/tasks/cucumber.rake

</pre>



<p>Here&#8217;s a brief description of what some of the important files do:</p>

<p>*<tt>config/cucumber.rb</tt>*: This is your cucumber environment, similar to <code>production.rb</code> or <code>development.rb</code>. Typically you&#8217;ll add cucumber specific <code>config.gem</code> directives and similar &#8220;cucumber only&#8221; items in here.</p>

<p>*<tt>features/step_definitions/web_steps.rb</tt>*: These are the webrat steps that you get for free with Cucumber and Webrat.</p>

<p>*<tt>features/support/env.rb</tt>*: This file has Cucumber specific setup and configuration options. This changes often, so it&#8217;s recommended to not alter this file directly, but to create your own custom <code>env.rb</code> (e.g. <code>custom_env.rb</code>).</p>

<p>*<tt>features/support/paths.rb</tt>*: Cucumber needs to be aware of the custom routes in your application that you plan on using when testing, this is where they are specified.</p>

<h4>Cucumber from 10,000ft</h4>

<p>Now that you&#8217;ve got your project configured to use Cucumber, let&#8217;s go over a high level view of the general concept of testing with Cucumber.</p>

<p>Cucumber uses &#8220;Features&#8221; to describe the functionality of your application. Features, stored in the <code>features</code> directory, are written in a simple human-readable format called <a href="http://wiki.github.com/aslakhellesoy/cucumber/gherkin">Gherkin</a>. The &#8220;Steps&#8221; in your feature files that describe the functionality of your application are backed up by step files in the <code>features/step_definitions</code> directory. The step files act like translations between the human-readable feature files and the underlying Ruby code of your Rails application.</p>

<p>Typically you will be using Cucumber in conjunction with Webrat to test your application. Webrat acts as the person behind the keyboard clicking around the site, filling out forms and viewing resulting pages. If you&#8217;ve ever tested your project by manually filling out forms and verifying output, that&#8217;s exactly what Webrat does for you, except it&#8217;s automated.</p>

<h4>Let&#8217;s Get Testing Already</h4>

<p>Rather than go into detail about <a href="http://en.wikipedia.org/wiki/Test-driven_development"><span class="caps">TDD</span></a> or <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development"><span class="caps">BDD</span></a> and why you should use them, I&#8217;m going to assume that you&#8217;re like most Rails developers looking to learn more about testing. You probably have an application or two out there in the wild, seemingly working just fine. However, you know that you should get some test coverage in there so that you can confidently make changes and debug problems as they come up. With that in mind, I am going to use a sample application that already has some functionality and we will add our Cucumber tests where needed.</p>

<h4>A Veterinary Patient Management System</h4>

<p>Our sample application is a simple patient management system for a Veterinarian that deals with Owners, Pets and Visitations. Let&#8217;s take a look at some of the models.</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
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> Owner <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
      has_many <span style="color:#ff3333; font-weight:bold;">:pets</span>
      validates_presence_of <span style="color:#ff3333; font-weight:bold;">:name</span>
      validates_presence_of <span style="color:#ff3333; font-weight:bold;">:email</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> Pet <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
      belongs_to <span style="color:#ff3333; font-weight:bold;">:owner</span>
&nbsp;
      validates_presence_of  <span style="color:#ff3333; font-weight:bold;">:name</span>
      validates_presence_of  <span style="color:#ff3333; font-weight:bold;">:species</span>
      validates_inclusion_of <span style="color:#ff3333; font-weight:bold;">:species</span>, :<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span> dog cat bird snake <span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Species: %s is not included in the list of accepted species&quot;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> Visitation <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
      has_one <span style="color:#ff3333; font-weight:bold;">:pet</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p>The first thing for which we&#8217;ll be adding a Feature is the process for creating a new Owner record. When a new client calls the Veterinarian&#8217;s office, an employee needs to enter them into the system.</p>

<h4>Writing a Feature</h4>

<p>Cucumber features are very straight forward. The feature file explains a set of functionality by describing different cases through scenarios.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="" style="font-family:monospace;">&nbsp;
    Feature: Manage Owners
      In order to value
      As a role
      I want feature
&nbsp;
      Scenario: title
        Given context
        When event
        Then outcome</pre></td></tr></table></div>




<p>Each Cucumber feature represents a desired software feature that a certain user of the system wants in order to achieve some end goal.  The scenarios are formatted so that a context is setup, an event occurs and an outcome is evaluated.</p>

<p>Let&#8217;s examine our real <code>Manage Owners</code> feature.</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
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="" style="font-family:monospace;">&nbsp;
    Feature: Managing Owners
      In order to manage our client list
      As an employee
      I want to be able to CRUD owners
&nbsp;
      Scenario: Creating a new Owner
        Given I am on the homepage
        And I follow &quot;Owners&quot;
        Then I should be on the owners index page
        Given I follow &quot;New owner&quot;
        And I fill in &quot;Name&quot; with &quot;Clayton&quot;
        And I fill in &quot;E-Mail&quot; with &quot;clayton@example.org&quot;
        And I fill in &quot;Address&quot; with &quot;<span style="">100</span> Cactus Rd&quot;
        And I fill in &quot;City&quot; with &quot;Scottsdale&quot;
        And I fill in &quot;State&quot; with &quot;Arizona&quot;
        And I fill in &quot;Postal Code&quot; with &quot;<span style="">85000</span>&quot;
        And I fill in &quot;Phone&quot; with &quot;<span style="">480</span>-<span style="">555</span>-<span style="">1212</span>&quot;
        When I press &quot;Create&quot;
        Then I should see &quot;Owner was successfully created.&quot;
        And I should be on the owners index page</pre></td></tr></table></div>




<p class="note">Note: When you specify &#8220;And&#8221; in a Cucumber feature the step inherits the Given/Then/When from the previous step</p>

<p>Our scenario covers the act of creating a new Owner record. We first setup a context (I am on the homepage). Next we click a link in the navigation (I follow &#8220;Owners&#8221;). Once we&#8217;re on the <code>index</code> view for the Owners controller (I should be on) we can click another link to get to the <code>new</code> view for the Owners controller. From there we are simply instructing Webrat to fill out our form (I fill in) and click the submit button at the bottom (I press &#8220;Create&#8221;). Finally we are asking Webrat to read the resulting page and see if there is some text present (I should see).</p>

<p>Our feature is looking pretty good, but we still have a few more steps before we can get this scenario passing. Running the this feature from the command line will give us some output and more direction. Once you&#8217;re run <code>rake db:migrate</code> and <code>rake db:test:prepare</code> run the following from your application&#8217;s root directory:</p>



<pre>

  ruby cucumber features/manage_owners.feature

</pre>



<p>Looks like we&#8217;re failing, and Cucumber gave us some information about what&#8217;s wrong.</p>



<pre>

  Can't find mapping from &quot;the owners index page&quot; to a path.
  Now, go and add a mapping in patient-management/features/support/paths.rb

</pre>



<p>If we open up our <code>features/support/paths.rb</code> file we can add the correct path right below the default path for the &#8220;home page&#8221;. The paths file is really just a list of regular expressions that Cucumber uses to match named routes to words in scenarios.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="" style="font-family:monospace;">&nbsp;
  when /the home\s?page/
    '/'
  when /the owners index page/
    owners_path</pre></td></tr></table></div>




<p>With that little change we have our first passing Cucumber scenario! When running Cucumber features from the command line, Cucumber will print out a little summary message.</p>



<pre>

    1 scenario (1 passed)
    14 steps (14 passed)
    0m0.290s

</pre>



<h4>Complex Scenario Setup</h4>

<p>In our above example the setup, or Given steps, were pretty simple. However, sometimes you need more complex setups for your scenarios, like editing a record for example. Cucumber makes it easy to create objects in your scenarios using tables in <a href="http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments">multiline step arguments</a>.</p>

<p>Here is a feature that goes through the process of editing an owner&#8217;s address. You&#8217;ll see the Cucumber table that is used to setup our existing owner record. The first row in the Cucumber table correspond to some of the attribute names for our Owner model.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="" style="font-family:monospace;">    Scenario: Editing an existing Owner
      Given the following owners:
       | name    | email               | address       |
       | Clayton | clayton@example.org | <span style="">100</span> Cactus Rd |
      Given I am on the homepage
      And I follow &quot;Owners&quot;
      Then I should be on the owners index page
      When I follow &quot;Edit&quot;
      And I fill in &quot;Address&quot; with &quot;<span style="">567</span> N Scottsdale Rd&quot;
      When I press &quot;Update&quot;
      Then I should see &quot;Owner was successfully updated.&quot;
      And I should be on the owners index page</pre></td></tr></table></div>




<p>When we try to run this, Cucumber will give us the &#8220;shell&#8221; for our custom step definition &#8220;Given the following owners&#8221;.</p>



<pre>
    Given /^the following owners:$/ do |table|
      # table is a Cucumber::Ast::Table
      pending # express the regexp above with the code you wish you had
    end
</pre>



<p>Since we never created a step definition for this Cucumber feature, we can go ahead and add a new file, <code>features/step_definitions/manage_owners_steps.rb</code>. It is important to note that Cucumber will load all of the files in <code>features/step_definitions</code> and that steps can be used across scenarios and features. If you think you&#8217;re going to re-use a step definition, it might be a good idea to place it in something like <code>features/step_definitions/shared_steps.rb</code>.</p>

<p class="note">Note: You should put some thought into your <a href="http://wiki.github.com/aslakhellesoy/cucumber/step-organisation">step organization</a> as your project grows in size.</p>

<p>Cucumber takes the table argument from your scenario and turns it into an array of hashes, which is technically a <code>Cucumber::Ast::Table</code> object. By iterating through each hash of the array, we can build up an object that we can use later in our tests. Since we want this object to live in the database and we don&#8217;t want to describe every attribute of the owner in our scenario, we can use Factory Girl to simplify the process.</p>

<p>The factory for our owner is simple. I won&#8217;t go into the specifics of how to create factories as that&#8217;s a whole other article. You can read more about using factories on the <a href="http://github.com/thoughtbot/factory_girl">github project page</a></p>

<p>Create a file to store your factories in <code>features/support/factories.rb</code> and copy the following.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'factory_girl'</span>
&nbsp;
    Factory.<span style="color:#9900CC;">define</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:owner</span><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>o<span style="color:#006600; font-weight:bold;">|</span>
      o.<span style="color:#9900CC;">name</span> <span style="color:#996600;">&quot;John Doe&quot;</span>
      o.<span style="color:#9900CC;">email</span> <span style="color:#996600;">&quot;john@example.org&quot;</span>
      o.<span style="color:#9900CC;">address</span> <span style="color:#996600;">&quot;123 Elm Street&quot;</span>
      o.<span style="color:#9900CC;">city</span> <span style="color:#996600;">&quot;Phoenix&quot;</span>
      o.<span style="color:#9900CC;">state</span> <span style="color:#996600;">&quot;Arizona&quot;</span>
      o.<span style="color:#9900CC;">zip</span> <span style="color:#996600;">&quot;85000&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p>When we use the factory to create our object, Factory Girl will take the attribute hash that we&#8217;ve passed in when creating the object and use those values for the object. Factory Girl will also fill in any blank attributes with the defaults we&#8217;ve specified in the factory definition. The record that is created will actually exist in the database, it is not a mock and it does not have any stubs, as far as our Rails app is concerned it is just a regular record in the database.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    Given <span style="color:#006600; font-weight:bold;">/</span>^the following owners:$<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>table<span style="color:#006600; font-weight:bold;">|</span>
      table.<span style="color:#9900CC;">hashes</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attributes<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#008000; font-style:italic;"># {:name =&gt; &quot;Clayton&quot;, :email =&gt; &quot;clayton@example.org&quot;, \</span>
        <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100 Cactus Rd&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:owner</span>, attributes<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p>Another place we could use our <code>Given the following owners</code> step would be when creating a feature that deals with creating Pet records. An owner <code>has_many</code> pets while a pet <code>belongs_to</code> an owner. When we create a pet record, we need an existing owner record to which we&#8217;ll link the pet record. Start by creating a new feature file, <code>features/manage_pets.feature</code>.</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
14
15
</pre></td><td class="code"><pre class="" style="font-family:monospace;">    Scenario: Creating a pet
      Given the following owners:
       | name    | email               |
       | Clayton | clayton@example.org |
      Given I am on the homepage
      And I follow &quot;Pets&quot;
      And I follow &quot;New pet&quot;
      When I fill in &quot;Name&quot; with &quot;Bruno&quot;
      And I select &quot;Dog&quot; from &quot;Species&quot;
      And I select &quot;March 19th, <span style="">2005</span>&quot; as the &quot;DOB&quot; date
      And I select &quot;Clayton <span class="br0">&#40;</span>clayton@example.org<span class="br0">&#41;</span>&quot; from &quot;Owner&quot;
      When I press &quot;Create&quot;
      Then I should see &quot;Bruno was successfully created.&quot;
      And I should be on the pets index page
      And a pet named &quot;Bruno&quot; should be owned by an owner named &quot;Clayton&quot;</pre></td></tr></table></div>




<p>In this example we have re-used our <code>Given the following owners</code> table. We have also made use of some new Webrat steps like <code>I select</code> for interacting with select lists and <code>I select [DATE] as the [DATE LABEL] date</code> for selecting a date from Rails&#8217; <code>date_selector</code> helper. Finally, there is a custom step that we are going to use to make sure that the connection between our newly created pet and the existing owner is in place.</p>

<p>Let&#8217;s take a look at the step definition for our custom step above.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
    <span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^a pet named <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> should be owned by an owner named <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>pet_name, owner_name<span style="color:#006600; font-weight:bold;">|</span>
      Pet.<span style="color:#9900CC;">find_by_name</span><span style="color:#006600; font-weight:bold;">&#40;</span>pet_name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">owner</span>.<span style="color:#9900CC;">name</span>.<span style="color:#9900CC;">should</span> == owner_name
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p>When you place something in double quotes in your scenario steps, like &#8220;Bruno&#8221; and &#8220;Clayton&#8221; in our example, they are captured using regular expressions in the step definition. Cucumber then passes the matched values along so that then can be used in your assertion. We can find the pet based on the <code>pet_name</code> and make sure that the <code>owner</code> linked to this pet via the <code>belongs_to</code> association is the same as the <code>owner_name</code> we specified in our scenario. This is an example of how Cucumber can be used, with RSpec matchers, to make an assertion that has nothing to do with inspecting the <span class="caps">DOM </span>of a resulting webpage.</p>

<p class="note">Note: Beware of the <a href="http://wiki.github.com/aslakhellesoy/cucumber/conjunction-steps-antipattern">Conjunction Steps</a> Anti-pattern</p>

<h4>Scenario Outlines</h4>

<p>Cucumber provides a very simple way to test multiple different situations with a single scenario. These might be edge cases or just repetitive examples that don&#8217;t require their own scenario.</p>

<p>We have some business logic in our application that determines when an appointment, or <code>Visitation</code>, can be made with the Veterinarian:</p>


<ul>
<li>Visitations less than three days from today require approval before being booked</li>
<li>No visitations can be booked more than six months in advance</li>
<li>No visitations can be booked in the past</li>
</ul>



<p>We can easily represent this using a Cucumber <a href="http://wiki.github.com/aslakhellesoy/cucumber/scenario-outlines">Scenario Outline</a>. Start by creating a new feature <code>features/visitation_logic.feature</code>. Also, because we&#8217;re going to be working with time and date specific business logic, this is a good time to point out that we can stub methods when using Cucumber, however, this practice is frowned upon and should only be used for things like dates and connecting to external <span class="caps">API</span>s.</p>

<p>To add stubbing support add the following to your <code>features/support/custom_env.rb</code> file.</p>



<pre>
  require 'spec/stubs/cucumber'
</pre>




<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="" style="font-family:monospace;">&nbsp;
    Scenario Outline: visitations
      Given the following owners:
        | name    |
        | Clayton |
      And the following pets:
        | name  |
        | Bruno |
      Given today is &quot;&lt;today&gt;&quot;
      Given I am on the home page
      And I follow &quot;Visitations&quot;
      And I follow &quot;New visitation&quot;
      And I select &quot;Bruno <span class="br0">&#40;</span>Owned by Clayton<span class="br0">&#41;</span>&quot; from &quot;Pet&quot;
      And I select &quot;&lt;date&gt;&quot; as the &quot;Appointment Date&quot; date
      When I press &quot;Create&quot;
      Then I should see &quot;&lt;message&gt;&quot;
&nbsp;
    Examples:
      | today      | date               | message                                           |
      | <span style="">2010</span>-01-01 | January 2nd, <span style="">2010</span>  | Visitation requires short notice approval.        |
      | <span style="">2010</span>-01-01 | January 31st, <span style="">2010</span> | Visitation succesfully created.                   |
      | <span style="">2010</span>-01-01 | November 2nd, <span style="">2010</span> | Visitations cannot be booked that far in advance. |
      | <span style="">2010</span>-04-01 | January 2nd, <span style="">2010</span>  | Visitations cannot be booked in the past.         |</pre></td></tr></table></div>




<p>Cucumber will go through the <code>Scenario Outline</code> you have created and substitute the values in &lt;&gt;&#8217;s with their corresponding value in the <code>Examples</code> table at the bottom. Cucumber goes through each line in the <code>Examples</code> table and runs the scenario using your specified values.</p>


<p>First, lets implement the step for stubbing our today&#8217;s date.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="" style="font-family:monospace;">&nbsp;
    Given /^today is &quot;<span class="br0">&#40;</span><span class="br0">&#91;</span>^\&quot;<span class="br0">&#93;</span>*<span class="br0">&#41;</span>&quot;$/ do |date|
      Date.stub<span class="br0">&#40;</span>:today<span class="br0">&#41;</span>.and_return<span class="br0">&#40;</span>Date.parse<span class="br0">&#40;</span>date<span class="br0">&#41;</span><span class="br0">&#41;</span>
    end</pre></td></tr></table></div>




<p>In <code>features/step_definitions/shared_steps.rb</code> we can add the implementation for <code>Given the following pets</code>. We are cheating here because we&#8217;re not explicitly linking the Pet to the Owner in our scenario outline. This example isn&#8217;t so bad, but keep in mind that this association is not obvious when reading the scenario. This type of &#8220;behind the scenes&#8221; scenario setup is generally a bad idea as it obscures what&#8217;s really happening. Since we&#8217;ve already created the owner we can just find the first one in the database and create the pet records using the appropriate Rails&#8217; association method.</p>



<pre>

    Given /^the following pets:$/ do |table|
      table.hashes.each do |attributes|
        Owner.first.pets.create(attributes)
      end
    end

</pre>



<p>The other steps in our scenario already exist, either because we created them, or because they come for free with the built in steps. In this one scenario we were able to test four different business logic outcomes. This test could be expanded to go beyond what is shown on the resulting page, perhaps to ensure that an Approval record was created for the short-notice appointment.</p>

<h4>Advanced Cucumber Goodies</h4>

<p>While you should now have an understanding of the basics of Cucumber, there are a number of other powerful features.</p>

<p><strong>Tags</strong></p>

<p>Cucumber allows you to &#8220;tag&#8221; your scenarios and features so that they can be run, not run or have special other tasks run before and after them. Out of the box you get the <code>@wip</code> tag (Work In Progress) which isn&#8217;t run as part of the normal <code>rake cucumber:ok</code> process.</p>

<p><strong>Hooks</strong></p>

<p>Using tags, you can run <code>Before</code> and <code>After</code> tasks that run some code before or after a given feature or scenario. You can even run these hooks before or after all of your features. You might need to do some cleanup of generated files in an After hook or some <span class="caps">CPU </span>expensive operation before a single scenario that you don&#8217;t want running before all of your scenarios.</p>

<p><strong>Table Transformations</strong></p>

<p>The tables that we have been creating use the exact model attribute names for their header rows. This is convenient for the developer, but makes the scenarios harder to understand. This is especially true if you have very strange or legacy attribute names like <code>record_quote_ext_type__c</code>. Using table transformations you can use &#8220;Record Extension Type&#8221; in your scenario table and map that to <code>record_quote_ext_type__c</code> in your step definition.</p>

<p><strong>Calling Steps from Steps</strong></p>

<p>It&#8217;s possible to take a multi-step process, expressed in Cucumber steps, and call them all at once from another step. You might have a few steps that describe logging in to a system (filling out login credentials, pressing a button etc.) You can easily put them all into one step, <code>Given I am logged in</code>, and then reference that elsewhere. This helps to reduce unnecessary repetition of steps and keep your scenarios to a manageable size.</p>

<p><strong>Profiles</strong></p>

<p>Cucumber allows you to specify a profile to use when running your features. By default Cucumber will not run any <code>@wip</code> tagged scenarios and the output will contain any failing files and the line number of the failure. However, if you wanted to run the <code>@production</code> tagged stories and output a nice <span class="caps">HTML </span>report, you could setup a new profile for that in <code>config/cucumber.yml</code> and use it when running your features.</p>

<p><strong>Testing Javascript</strong></p>

<p>You can even use Cucumber to test complex javascript. Tools like <a href="http://celerity.rubyforge.org/">Celerity</a> with <a href="http://github.com/langalex/culerity">Culerity</a> or <a href="http://seleniumhq.org/">Selenium</a> give you the ability go beyond the interactions provided by Webrat. A new addition to Cucumber is <a href="http://github.com/jnicklas/capybara">Capybara</a> support which aims to unify the language used in steps so that you can use Webrat, Selenium and Celerity side-by-side.</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2010/03/zero-to-tested-with-cucumber-and-factory-girl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use Cucumber Table Transformations To Build Objects</title>
		<link>http://www.claytonlz.com/index.php/2010/01/cucumber-table-transformations/</link>
		<comments>http://www.claytonlz.com/index.php/2010/01/cucumber-table-transformations/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:30:02 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber testing rails guide]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=397</guid>
		<description><![CDATA[Using Cucumber&#8217;s Table Transformations, you can easily build complex objects in a way that&#8217;s easy to read and understand for clients and developers alike. My latest favorite feature of Cucumber are Table Transformations. I frequently use tables to build up complex objects and I&#8217;ve found that the regular old tables can be a little ugly, [...]]]></description>
			<content:encoded><![CDATA[<p></p><h3>Using Cucumber&#8217;s Table Transformations, you can easily build complex objects in a way that&#8217;s easy to read and understand for clients and developers alike.</h3>

<p>My latest favorite feature of Cucumber are <a href="http://wiki.github.com/aslakhellesoy/cucumber/step-argument-transforms">Table Transformations</a>. I frequently use tables to build up complex objects and I&#8217;ve found that the regular old tables can be a little ugly, especially when your attribute names don&#8217;t make much sense on their own. I&#8217;ve also noticed that building up associations can be a little wonky, usually requiring more steps than seem necessary.</p>

<h4>Conventional Table Usage</h4>

<p>Let&#8217;s look at an example of how we could use a table, without transformations, to build up some objects for our scenario.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Scenario: Editing a Spirit
  Given I have a spirit with the following attributes:
    | spirit_type    | country_of_origin | age | brand        | lgcy_prod_sku | name       |
    | Scotch Whisky  | Scotland          | <span style="">12</span>  | The Balvenie | SC38181       | DoubleWood |
    | Scotch Whiskey | Scotland          | <span style="">12</span>  | The Macallan | SC38245       |            |</pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Given /^I have a spirit with the following attributes:$/ do |table|
  table.hashes.each do |attributes|
    Spirit.create!<span class="br0">&#40;</span>attributes<span class="br0">&#41;</span>
  end
end</pre></td></tr></table></div>




<p class="alert">Be sure to use <code>create!</code> in your tests to prevent false positives (Thanks Aslak!)</p>

<p>Now this is all fairly simple, and it looks pretty easy to implement, but I see some problems. First, what if you were actually friends with your <span class="caps">DBA </span>(bear with me) and you knew better than to have an attribute in your model like <code>country_of_origin</code> or <code>spirit_type</code>. Chances are those are going to be used by many other records and should be pulled out and made into their own Models, <code>Country</code> and <code>SpiritType</code> respectively.<sup class="footnote"><a href="#fn1">1</a></sup></p>

<p>So what does our scenario look like with those two new models?</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Scenario: Editing a Spirit
  Given I have a country with the following attributes:
    | name     | continent |
    | Scotland | Europe    |
  And I have a spirit type with the following attributes:
    | name           |
    | Scotch Whiskey |
  And I have a spirit with the following attributes:
    | age | brand        | lgcy_prod_sku | name       |
    | <span style="">12</span>  | The Balvenie | SC38181       | DoubleWood |
    | <span style="">12</span>  | The Macallan | SC38245       |            |</pre></td></tr></table></div>




<p>It&#8217;s a little more complex, for sure, but it&#8217;s not totally unmanageable. However, the key part that&#8217;s missing is how to link the two spirits with their spirit types and countries of origin.</p>

<p>You could add some more steps, but then you&#8217;ve got a <a href="http://wiki.github.com/aslakhellesoy/cucumber/conjunction-steps-antipattern">conjunction step</a> which is inflexible and brittle.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="" style="font-family:monospace;">  And the spirit named &quot;The Balvenie&quot; is from &quot;Scotland&quot; and is a &quot;Scotch Whiskey&quot;</pre></td></tr></table></div>




<p>You could go back to your original step, and try to do some behind-the-scenes stuff to map <code>country_of_origin</code> to the correct <code>country_id</code>, but that gets messy too.</p>

<h4>Transform Your Tables</h4>

<p>The first step to making good use of table transformations is to make your tables more readable. Start by change the header row of your table to use meaningful representations of the real attribute names.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Given I have a spirit with the following attributes:
  | Spirit Type    | Country  | Age | Brand        | Legacy Product Code | Name       |
  | Scotch Whisky  | Scotland | <span style="">12</span>  | The Balvenie | SC38181             | DoubleWood |
  | Scotch Whiskey | Scotland | <span style="">12</span>  | The Macallan | SC38245             |            |</pre></td></tr></table></div>




<p>We&#8217;ve turned that weird <code>lgcy_prod_sku</code> attribute into something that your Product Owner can make sense of and we&#8217;ve be able to add <code>Spirit Type</code> and <code>Country of Origin</code> back to the table. Now let&#8217;s look at the transformation that makes this all work.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Transform /^table:Spirit Type,Country,Age,Brand,Legacy Product Code,Name$/ do |table|
  table.hashes.map do |hash|
    spirit_type = SpiritType.create!<span class="br0">&#40;</span><span class="br0">&#123;</span>:name =&gt; hash<span class="br0">&#91;</span>&quot;Spirit Type&quot;<span class="br0">&#93;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>
    country = Country.create!<span class="br0">&#40;</span><span class="br0">&#123;</span>:name =&gt; hash<span class="br0">&#91;</span>&quot;Country&quot;<span class="br0">&#93;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>
    spirit = Spirit.create!<span class="br0">&#40;</span><span class="br0">&#123;</span>:age =&gt; hash<span class="br0">&#91;</span>&quot;Age&quot;<span class="br0">&#93;</span>,
                            :brand =&gt; hash<span class="br0">&#91;</span>&quot;Brand&quot;<span class="br0">&#93;</span>,
                            :lgcy_prod_sku =&gt; hash<span class="br0">&#91;</span>&quot;Legacy Product Code&quot;<span class="br0">&#93;</span>,
                            :name =&gt; hash<span class="br0">&#91;</span>&quot;Name&quot;<span class="br0">&#93;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>
&nbsp;
    <span class="br0">&#123;</span>:spirit_type =&gt; spirit_type, :country =&gt; country, :spirit =&gt; spirit<span class="br0">&#125;</span>
  end
end</pre></td></tr></table></div>




<p>The transformation step definition looks a lot like a regular table step definition. There is a regular expression, like anything else in Cucumber, that has the same values as the header row in the table from our scenario. Just like the table step definition we have a table object which is just an array of hashes. We can go through each hash, do the actual transformation, and then return something to our table step definition. We are using <code>map</code> (same as <code>collect</code>) to return an array of hashes, which is just what the table step definition is expecting.</p>

<p>You will also see that we&#8217;re creating three different records, which we are returning in the hash we create at the end. Let&#8217;s go through those step-by-step:</p>


<ol>
<li>Create a spirit type object from the <code>hash[&quot;Spirit Type&quot;]</code> value</li>
<li>Create a country object from the <code>hash[&quot;Country&quot;]</code> value</li>
<li>Create a spirit object from the several related hash values</li>
<li>Put all of our created objects into a hash</li>
</ol>



<p>While we&#8217;ve created the objects, we still need to create the associations. I like to leave this for the table step definition rather than the transformation since I think it&#8217;s more obvious what&#8217;s going on with the values when you&#8217;re viewing the table step.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="" style="font-family:monospace;">Given /^I have a spirit with the following attributes:$/ do |table|
  table.each do |group|
    spirit = group<span class="br0">&#91;</span>:sprit<span class="br0">&#93;</span>
    associations = <span class="br0">&#123;</span>:country =&gt; group<span class="br0">&#91;</span>:country<span class="br0">&#93;</span>, :spirit_type =&gt; group<span class="br0">&#91;</span>:spirit_type<span class="br0">&#93;</span><span class="br0">&#125;</span>
    spirit.update_attributes<span class="br0">&#40;</span>associations<span class="br0">&#41;</span>
  end
end</pre></td></tr></table></div>




<p>There are at least a dozen ways to get the spirit associated with the country and spirit type, so don&#8217;t feel like you have to follow this pattern every time. Since we&#8217;ve sent our table an array of hashes we can iterate over each hash, <code>group</code>, and work with the individual rows. Here&#8217;s how:</p>


<ol>
<li>Extract the spirit object from the hash</li>
<li>Create another hash with the country and spirit type that Rails can make sense of</li>
<li>Use <code>update_attributes</code> to update the spirit object with the new associations</li>
</ol>



<h4>Transformation Tradeoffs</h4>

<p>We&#8217;ve been able to take our original multi-step scenario and simplify it to a single step. We are using the proper place, the step definitions, to do the associations and we have made our scenario much easier to read for non-developers working on the project. But what did we give up?</p>

<p>The biggest issue I&#8217;ve found with using table transformations is that they can be inflexible when you need to add more attributes to your dynamically created object. If you are writing features, using your table to setup objects and then realize that you need to add another attribute, you&#8217;re going to have to edit your table transformation step and how you create objects from the hash. When you take this a step further and try to have two different table definitions, you&#8217;ll be looking at having two nearly identical table transformations.<sup class="footnote"><a href="#fn2">2</a></sup></p>

<p>If you&#8217;re not already using regular old Cucumber tables to create objects, use this guide to get started. If you are using Cucumber tables to create objects, try to re-factor one of your scenarios and use the table transformation strategy. Once you start using Cucumber tables and table transformations you&#8217;ll instantly improve the readability, portability and efficiency of your steps.</p>


<p class="footnote" id="fn1"><sup>1</sup> Ignore for now the issues with <code>spirit_type</code> and Rails Single Table Inheritance</p>

<p class="footnote" id="fn2"><sup>2</sup> I&#8217;m guessing that there is some way you can get around this with regular expressions and to have more flexible transformation table steps, but I haven&#8217;t tried it yet.</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2010/01/cucumber-table-transformations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Do You Make This Common Mistake When Estimating?</title>
		<link>http://www.claytonlz.com/index.php/2010/01/the-common-estimation-mistake/</link>
		<comments>http://www.claytonlz.com/index.php/2010/01/the-common-estimation-mistake/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 17:30:09 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[Estimating]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=388</guid>
		<description><![CDATA[There&#8217;s a common mistake that many software developers make when estimating projects. Here&#8217;s how you can avoid falling into this trap. When estimating a project using the Planning Poker method, many developers like to use a baseline estimate for a given task. For example, many developers use CRUD, the creating, displaying, editing and deleting of [...]]]></description>
			<content:encoded><![CDATA[<p></p><h3>There&#8217;s a common mistake that many software developers make when estimating projects. Here&#8217;s how you can avoid falling into this trap.</h3>

<p>When estimating a project using the <a href="http://www.planningpoker.com/">Planning Poker</a> method, many developers like to use a baseline estimate for a given task. For example, many developers use <span class="caps">CRUD, </span>the creating, displaying, editing and deleting of a Model as their baseline estimate. Once they&#8217;ve got their baseline in mind, it makes it easier to estimate other stories that are more domain specific, or so it seems.</p>

<h4>Baseline Estimates are Broken</h4>

<p>When you&#8217;re using a task like <span class="caps">CRUD </span>as a baseline for your estimations, you can easily skew the estimations of the other stories in the project. Let&#8217;s say we&#8217;re using a 3 point baseline for <span class="caps">CRUD </span>stories.</p>


<ol>
<li>As a user I should be able to upload a profile photo &#8211; 2</li>
<li>As a user I should be able to <span class="caps">CRUD </span>movies I&#8217;ve seen &#8211; 3</li>
<li>As a user I should be able to send a private message to another user &#8211; 5</li>
<li>As a user I should be able to create a trivia quiz for a movie that I&#8217;ve seen &#8211; 8</li>
</ol>



<p>In this first example, the stories are probably estimated fairly well and compared to each other, the complexity is quite relative. What happens if we add a few more easy stories or a few more difficult stories?</p>


<ol>
<li>As a user I should be able to see a contact e-mail on the home page &#8211; 1</li>
<li>As a user I should be able download the menu as a <span class="caps">PDF </span>- 1</li>
<li>As a user I should be able to read a privacy policy &#8211; 2</li>
<li>As a user I should be able to <span class="caps">CRUD </span>restaurant reviews &#8211; 3</li>
</ol>



<p>With easier stories added, the <span class="caps">CRUD </span>story is definitely the most complex, but compared to the others it is significantly <em>more</em> complex than seeing a link on a page or viewing some text.</p>


<ol>
<li>As a user I should be able to <span class="caps">CRUD </span>portfolio photos &#8211; 3</li>
<li>As a user I should be able to signup for a paid recurring account &#8211; 8</li>
<li>As a user I should be able to make connections with other users via Facebook &#8211; 13</li>
<li>As a user I should be able to send a rocket to the moon &#8211; !</li>
</ol>



<p>When the other stories become much more complex, the <span class="caps">CRUD </span>task is again shown to be significantly different in complexity, this time in the other direction. In this group of stories its hard to imagine that managing portfolio photos is only two orders of magnitude away from a recurring payment e-commerce system.</p>

<h4>Relative Complexity Works</h4>

<p>Its important to estimate a group of stories so that the complexity of each story is relative to the next. In Mike Cohn&#8217;s <cite>Agile Estimating and Planning</cite>, he describes a method of estimating stories called &#8220;Analogy&#8221;. </p>

<blockquote><p>When estimating by analogy, the estimator compares the story being estimated with one or more other stories. If the story is twice the size, it is given an estimate twice as large.</p></blockquote>

<p>When you apply this technique to your estimation process, you will have a more coherent set of estimates. From this you will be more likely to determine an accurate estimated velocity and you will have a better overall sense for the scope of the project. </p>

<h4>Hurdles to Estimating by Analogy</h4>


<ul>
<li>Estimating all of your stories one by one makes it difficult to estimate a relative complexity as you only have the previously estimated stories with which to compare your current story. A group of especially simple or complex stories could be waiting towards the end of the sessions.</li>
<li>Estimators who are new to the agile estimation process might have difficultly estimating a story without a point of reference.</li>
<li>Estimating with a baseline can be a difficult habit to break since it provides a convenience and familiarity to the estimator.</li>
<li>Two seemingly similar projects may have a greater than expected difference in total number of story points, even though their velocities are relatively the same.</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2010/01/the-common-estimation-mistake/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Secret to Awesome Agile Development</title>
		<link>http://www.claytonlz.com/index.php/2009/12/awesome-agile-development-secret/</link>
		<comments>http://www.claytonlz.com/index.php/2009/12/awesome-agile-development-secret/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 17:30:40 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=367</guid>
		<description><![CDATA[With a little hard work and my secret development ingredient, you can be a better Agile Developer Recently my fellow developers at Integrum and I took a survey that helped us assess our team with regard to our Agile practices. When taking the survey, and now reviewing it later on, I was struck by how [...]]]></description>
			<content:encoded><![CDATA[<p></p><h3>With a little hard work and my secret development ingredient, you can be a better Agile Developer</h3>

<p><span class="drop_cap">R</span>ecently my fellow developers at <a href="http://www.integrumtech.com">Integrum</a> and I took a survey that helped us assess our team with regard to our Agile practices. When taking the survey, and now reviewing it later on, I was struck by how many of the questions were related to a single concept. Many of the problem areas that can be uncovered by the survey, along with examples of one&#8217;s successes, come back to this one theme.</p>

<blockquote class="left">Are programmers nearly always confident that the code they&#8217;ve written recently does what it&#8217;s intended to do?
</blockquote>Consider the following questions:


<ul>
<li>Is there more than one bug per month in the business logic of completed stories?</li>
<li>Can any programmer on the team currently build and test the software, and get unambiguous success / fail result, using a single command?</li>
<li>When a programmer gets the latest code, is he nearly always confident that it will build successfully and pass all tests?</li>
<li>Are fewer than five bugs per month discovered in the team&Ecirc;&frac14;s finished work?</li>
<li>After a line item is marked &#8220;complete&#8221; do team members later perform unexpected additional work, such as bug fixes or release polish, to finish it?</li>
<li>Are programmers nearly always confident that the code they&#8217;ve written recently does what it&#8217;s intended to do?</li>
<li>Are all programmers comfortable making changes to the code?</li>
<li>Do programmers have more than one debug session per week that exceeds 10 minutes?</li>
<li>Do unexpected design changes require difficult or costly changes to existing code?</li>
<li>Do any programmers optimize code without conducting performance tests first?</li>
<li>Is there more than one bug per month in the business logic of completed stories?</li>
<li>Are any team members unsure about the quality of the software the team is producing?</li>
</ul>



<p class="alert">What&#8217;s the common theme among these stories, and the secret to better agile development? <strong>Testing</strong>, <strong>testing</strong> and more <strong>testing</strong>.</p>

<p>The negative outcomes implied by some of these questions can be solved by testing. Spending time fixing &#8220;completed&#8221; stories? Probably something you could have tested. Conversely, the positive benefits implied by other questions can be had via testing. Want to make your code more inviting and easier to deal with for new team members or people unfamiliar with the project? Give them robust and well-written tests.</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/12/awesome-agile-development-secret/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The 7 Bullshit Agile Estimation Problems</title>
		<link>http://www.claytonlz.com/index.php/2009/12/agile-esitmation-problems/</link>
		<comments>http://www.claytonlz.com/index.php/2009/12/agile-esitmation-problems/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 18:15:04 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Riffs]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[estimations]]></category>
		<category><![CDATA[planning]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=332</guid>
		<description><![CDATA[Estimating stories for an upcoming project is one of the more difficult tasks that agile teams have to perform. It&#8217;s never easy to determine how difficult it will be to implement a particular feature, especially when you&#8217;ve got different personalities, goals, and levels or experience in the same room. Unfortunately this all leads to people [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Estimating stories for an upcoming project is one of the more difficult tasks that agile teams have to perform. It&#8217;s never easy to determine how difficult it will be to implement a particular feature, especially when you&#8217;ve got different personalities, goals, and levels or experience in the same room. Unfortunately this all leads to people coming up with excuses and roadblocks which lead to inaccurate estimates.</p>

<p>I&#8217;ve identified seven problems pitfalls of the agile estimation process that I&#8217;m sure many other teams have experienced:</p>

<h3>1) Estimating Time Rather Than Complexity</h3>

<p>The point of estimating stories with planning poker cards is that you estimate based on the story&#8217;s complexity, not on how long it will take you to complete the actual feature. A story that&#8217;s an 8 is more complex than one that&#8217;s a 5, but it doesn&#8217;t meant that the 8 will take two days. It could take an hour or a week, it&#8217;s all relative.</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
Estimates based on time make planning commitments difficult and velocities unreliable.</p>

<h3>2) Not Estimating For &#8220;Simplest Possible Solution&#8221;</h3>

<p>The &#8220;Simplest Possible Solution&#8221; is just that, what&#8217;s the simplest way that the feature described in the story can be implemented. When you get away from this you start going down all sorts of &#8220;what if&#8221; roads that always end up bumping up your estimate.</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
Trying to guess what the product owner will want or what the completed feature entails is a waste of time.</p>

<h3>3) I&#8217;ve Never Done That Before</h3>

<p>There aren&#8217;t many software problems that haven&#8217;t been solved. Most of them are things that have been solved a thousand times in a hundred different ways. Adding complexity to a story because you&#8217;ve personally never solved that problem is shortsighted.</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
Just because you&#8217;ve never done something doesn&#8217;t mean it&#8217;s complex. Lean on your team or network of developer peers to help solve these problems.</p>

<h3>4) Estimating Stories In Excessive or No Isolation</h3>

<p>Stories should be estimated in isolation, just as they should be written so as not to depend heavily on one another.  However, developers will often try to assign too much complexity to a story because of assumed tasks or features that <em>they think</em> would accompany the story in a completed state. For example:</p>

<blockquote>
As a user I should be able to login<br />
As a user I should be able to upload a profile photo<br />
As a user I should be able to change my address<br />
</blockquote>

<p>Some developers will see the first story and immediately think of the complexity of creating a user model, the controllers and views that go along with the entire registration process. </p>

<p>Alternatively some developers will see the last story and think &#8220;Oh I just need a form field for the e-mail address when the user is editing their profile.&#8221;</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
The first extreme gives you chunks of related stories with too much padding that are never as complex individually as they are as a whole. The latter only (sometimes) works when the actual stories are extracted out into a bunch of very small stories, which has its own set of problems.</p>

<h3>5) Gaming Velocities</h3>

<p>If you&#8217;re looking to &#8220;guesstimate&#8221; how long a project will take to complete, you could grab some story cards and pick out what you think might be a week of work. If you add up the points assigned to those stories you&#8217;d have an estimated velocity. However, if you&#8217;ve padded your stories, or purposefully pick out a small number of stories, your project is going to appear much lengthier than it really is.</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
You don&#8217;t look any better completing 50 points per iteration when you padded the hell out of your estimates than you do when you do 20 points per iteration with accurate estimates.</p>

<h3>6) Always Assume The Worst!</h3>

<p>There seems to be this mantra with some developers, &#8220;Always assume the worst!&#8221; When you come across a slightly vague story, let your imagination run wild and assume that the product owner is going to want the most complex solution possible.</p>

<p><strong>Why it&#8217;s Bullshit</strong><br />
Remember, every story is a negotiation. You&#8217;re not going to know the exact details of the story until you have your planning meeting with the product owner. Often times the product owner would never have been able to dream up the solution on which you based your estimate. </p>

<h3>7) Padding Padding Padding</h3>

<p><strong>Padding is all Bullshit</strong><br />
The problem of padding estimates creeps into nearly all of the above six issues. It introduces bad data early in the life of the project and makes every other step of the process unreliable. It&#8217;s almost always in an effort to cover one&#8217;s ass but it&#8217;s painfully transparent and reeks of amateurism.</p>

<p>Don&#8217;t pad your estimates.</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/12/agile-esitmation-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intel Developer Ignite #2</title>
		<link>http://www.claytonlz.com/index.php/2009/11/intel-developer-ignite-2/</link>
		<comments>http://www.claytonlz.com/index.php/2009/11/intel-developer-ignite-2/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 17:30:49 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Social Networking]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=327</guid>
		<description><![CDATA[I had a blast presenting at the recent Intel Developer Ignite. In my quick five minute presentation I mapped ten of Aesop&#8217;s fables to modern day software engineering challenges and principles. If you missed the event, or just want to check out my presentation again, here it is! Age-Old Solutions to Everyday Problems Big thanks [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I had a blast presenting at the recent Intel Developer Ignite. In my quick five minute presentation I mapped ten of Aesop&#8217;s fables to modern day software engineering challenges and principles. If you missed the event, or just want to check out my presentation again, here it is!</p>

<p><a href="http://software.intel.com/en-us/videos/34age-old-solutions-to-everyday-problems34/">Age-Old Solutions to Everyday Problems</a></p>

<p>Big thanks to Intel and everyone involved for putting on a great event, I really enjoyed it and can&#8217;t wait to do it again soon.</p>

<p><object id='v_2676_1145' name='v_2676_1145' width='640' height='360' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'><param name='flashvars' value='file=http://software.intel.com/media/videos/f/e/a/b/0/5/a/feab05aa91085b7a8012516bc3533958.flv&amp;image=http://software.intel.com/media/videos/f/e/a/b/0/5/a/feab05aa91085b7a8012516bc3533958_player.jpg&amp;autostart=false&amp;bufferlength=5&amp;allowfullscreen=true&amp;plugins=http://software.intel.com/common/swf/listen&amp;title=%26%2334%3BAge-Old+Solutions+to+Everyday+Problems%26%2334%3B' /><param name='movie' value='http://software.intel.com/common/swf/mediaplayer.swf' /><param name='allowfullscreen' value='true' /><embed src='http://software.intel.com/common/swf/mediaplayer.swf' width='640' height='360' bgcolor='#FFFFFF' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='file=http://software.intel.com/media/videos/f/e/a/b/0/5/a/feab05aa91085b7a8012516bc3533958.flv&amp;image=http://software.intel.com/media/videos/f/e/a/b/0/5/a/feab05aa91085b7a8012516bc3533958_player.jpg&amp;autostart=false&amp;bufferlength=5&amp;allowfullscreen=true' allowfullscreen='true'/></object></p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/11/intel-developer-ignite-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Secret to Full Stack Testing with Cucumber and Webrat</title>
		<link>http://www.claytonlz.com/index.php/2009/11/the-secret-to-full-stack-testing-with-cucumber-and-webrat/</link>
		<comments>http://www.claytonlz.com/index.php/2009/11/the-secret-to-full-stack-testing-with-cucumber-and-webrat/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 00:54:48 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[cucumber]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=318</guid>
		<description><![CDATA[Today I gave a presentation at "Desert Code Camp":http://www.desertcodecamp.com/ about BDD, Cucumber, Webrat and User Stories. If you'd like to find review the slides or download the code I used during the presentation here they are.]]></description>
			<content:encoded><![CDATA[<p></p><p>Today I gave a presentation at <a href="http://www.desertcodecamp.com/">Desert Code Camp</a> about <span class="caps">BDD,</span> Cucumber, Webrat and User Stories. If you&#8217;d like to find review the slides or download the code I used during the presentation here they are.</p>

<h3>Slides and Code</h3>

<p><a href="http://www.claytonlz.com/wp-content/uploads/2009/11/slides.pdf">Desert Code Camp <span class="caps">BDD</span> Presentation Slides</a></p>

<p><a href="http://github.com/clayton/desert-code-camp" target="_self">http://github.com/clayton/desert-code-camp</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/11/the-secret-to-full-stack-testing-with-cucumber-and-webrat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cucumber Table Transformations with Factory Girl Sequences</title>
		<link>http://www.claytonlz.com/index.php/2009/11/cucumber-table-transformations-with-factory-girl-sequences/</link>
		<comments>http://www.claytonlz.com/index.php/2009/11/cucumber-table-transformations-with-factory-girl-sequences/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 17:33:49 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[factory_girl]]></category>
		<category><![CDATA[transformations]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=313</guid>
		<description><![CDATA[If you're using "Cucumber":http://cukes.info and you're not using "Transformations":http://wiki.github.com/aslakhellesoy/cucumber/step-argument-transforms you're doing it wrong. I just started using these recently and ran into a problem with creating records using "Factory Girl":http://github.com/thoughtbot/factory_girl factories that made use of sequences. While trying to create multiple "Authlogic":http://github.com/binarylogic/authlogic user records with a unique <tt>email</tt> and unique <tt>single_access_token</tt> using a Cucumber table, the functionality of <tt>Factory.next(:email)</tt> wasn't working correctly, I would always get the same e-mail address. Turns out it was an easy fix, just had to use lazy attributes in my factory.]]></description>
			<content:encoded><![CDATA[<p></p><p>If you&#8217;re using <a href="http://cukes.info">Cucumber</a> and you&#8217;re not using <a href="http://wiki.github.com/aslakhellesoy/cucumber/step-argument-transforms">Transformations</a> you&#8217;re doing it wrong. I just started using these recently and ran into a problem with creating records using <a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> factories that made use of sequences. While trying to create multiple <a href="http://github.com/binarylogic/authlogic">Authlogic</a> user records with a unique <tt>email</tt> and unique <tt>single_access_token</tt> using a Cucumber table, the functionality of <tt>Factory.next(:email)</tt> wasn&#8217;t working correctly, I would always get the same e-mail address. Turns out it was an easy fix, just had to use lazy attributes in my factory.</p>

<h4>The Scenario, Step Definition and Factory</h4>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="" style="font-family:monospace;">  Scenario: Presenter List
    Given the following presenters:
      | Name    | Bio                 | Website              |
      | Clayton | Rails dev @integrum | http://claytonlz.com |
      | Chris   | Scrum @integrum     |                      |
    And I am on the homepage
    When I follow &quot;Presenters&quot;
    Then I should see &quot;Clayton&quot;
    And I should see &quot;Rails dev @integrum&quot;
    And I should see &quot;http://claytonlz.com&quot;
    Then I should see &quot;Chris&quot;
    And I should see &quot;Scrum @integrum&quot;</pre></td></tr></table></div>




<p><strong>My  Step Definition</strong><br />
This uses the Transformation table below:</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;">Given <span style="color:#006600; font-weight:bold;">/</span>^the following presenters:$<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>table<span style="color:#006600; font-weight:bold;">|</span>
  table.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attrs<span style="color:#006600; font-weight:bold;">|</span>
    Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user</span>, attrs<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p>This transformation takes a table like the one in my scenario above, and assigns the values to a hash using the actual model attribute names (Name isn&#8217;t an attribute on a user but name is). The regular cucumber step definition &#8220;consumes&#8221; this hash for each entry in the table and passes it to a Factory for creation.</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;">Transform <span style="color:#006600; font-weight:bold;">/</span>^table:Name,Bio,Website$<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>table<span style="color:#006600; font-weight:bold;">|</span>
  table.<span style="color:#9900CC;">hashes</span>.<span style="color:#9900CC;">map</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>hash<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#006600; font-weight:bold;">&#123;</span>:name <span style="color:#006600; font-weight:bold;">=&gt;</span> hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:Name</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:bio</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:Bio</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:website</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:Website</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p><strong>My Factory</strong></p>

<p>This is a pretty basic factory for an authlogic user model, I&#8217;m using factory_girl sequences to give me a &#8220;unique&#8221; e-mail and single access token, which are required by Authlogic.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:user</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>user<span style="color:#006600; font-weight:bold;">|</span>
  user.<span style="color:#9900CC;">email</span> Factory.<span style="color:#9966CC; font-weight:bold;">next</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  user.<span style="color:#9900CC;">name</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">bio</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">website</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">password</span> <span style="color:#996600;">&quot;password&quot;</span>
  user.<span style="color:#9900CC;">password_confirmation</span> <span style="color:#996600;">&quot;password&quot;</span>
  user.<span style="color:#9900CC;">single_access_token</span> Factory.<span style="color:#9966CC; font-weight:bold;">next</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:single_access_token</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<h4>The problem</h4>

<p>The above scenario will fail when it tries to create the user records via the factories. You&#8217;ll see a validation error about how the user model requires a unique e-mail and single access token. You&#8217;ll be wondering, &#8220;hey why are my sequences working?&#8221;. When you inspect the log you&#8217;ll see that they are in fact <span class="caps">NOT </span>working.</p>

<h4>The Quick Answer</h4>

<p>The easy answer to this is that you need to use lazy attributes in your factory for the sequences so that they are loaded each time instead of once.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:user</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>user<span style="color:#006600; font-weight:bold;">|</span>
  user.<span style="color:#9900CC;">email</span> <span style="color:#006600; font-weight:bold;">&#123;</span> Factory.<span style="color:#9966CC; font-weight:bold;">next</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  user.<span style="color:#9900CC;">name</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">bio</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">website</span> <span style="color:#996600;">&quot;&quot;</span>
  user.<span style="color:#9900CC;">password</span> <span style="color:#996600;">&quot;password&quot;</span>
  user.<span style="color:#9900CC;">password_confirmation</span> <span style="color:#996600;">&quot;password&quot;</span>
  user.<span style="color:#9900CC;">single_access_token</span> <span style="color:#006600; font-weight:bold;">&#123;</span> Factory.<span style="color:#9966CC; font-weight:bold;">next</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:single_access_token</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>




<p><strong>Notice the curly braces around the sequences</strong></p>

<h4>The Longer Answer</h4>

<p>The cucumber rdoc explains the Transform functionality, albeit somewhat hard to understand.</p>

<blockquote><p>Registers a proc that will be called with a step definition argument if it matches the pattern passed as the first argument to Transform. Alternatively, if the pattern contains captures then they will be yielded as arguments to the provided proc. The return value of the proc is consequently yielded to the step definition.</p></blockquote>

<p>I think the issue comes from something with the way these Procs are created, called and also their scope with regard to the step definition etc. I don&#8217;t think my ruby-fu is strong enough to give a good explanation but maybe I&#8217;m going in the right direction.</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/11/cucumber-table-transformations-with-factory-girl-sequences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing host to link to! Please provide :host parameter</title>
		<link>http://www.claytonlz.com/index.php/2009/11/authlogic-activation-host-parameter-gotcha/</link>
		<comments>http://www.claytonlz.com/index.php/2009/11/authlogic-activation-host-parameter-gotcha/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:53:46 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[activation]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[gotcha]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=305</guid>
		<description><![CDATA[If you've followed my version of the "authlogic account activation tutorial":http://www.claytonlz.com/index.php/2009/07/authlogic-account-activation-tutorial/ or the "original version":http://github.com/matthooks/authlogic-activation-tutorial by Matt Hooks you might have run into this error]]></description>
			<content:encoded><![CDATA[<p></p><p>If you&#8217;ve followed my version of the <a href="http://www.claytonlz.com/index.php/2009/07/authlogic-account-activation-tutorial/">authlogic account activation tutorial</a> or the <a href="http://github.com/matthooks/authlogic-activation-tutorial">original version</a> by Matt Hooks you might have run into this error:</p>

<code>
Missing host to link to! Please provide :host parameter or set default_url_options[:host] when sending emails
</code>

<p>When authlogic sends e-mails with the account activation link, it uses a <tt>url_for</tt> helper to build that link. Because the &#8220;Notifier&#8221; mailer is an instance of <tt>ActionMailer::Base</tt> and not <tt>ActionController::Base</tt> it doesn&#8217;t know what the <tt>host</tt> parameter of the <span class="caps">URL </span>should be, so you have to tell it explicitly.</p>

<p>Put the following into your <tt>environments/development.rb</tt> and <tt>environments/test.rb</tt>:</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:#008000; font-style:italic;"># This assumes you're running your local development server on port 3000 via script/server</span>
config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">default_url_options</span> = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:host</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;127.0.0.1:3000&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>




<p>Put this into your <tt>environments/production.rb</tt>:</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:#008000; font-style:italic;"># Replace example.org with your actual domain name</span>
config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">default_url_options</span> = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:host</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;example.org&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/11/authlogic-activation-host-parameter-gotcha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Make Fun of Your Client To Prevent Defects</title>
		<link>http://www.claytonlz.com/index.php/2009/10/make-fun-of-your-client/</link>
		<comments>http://www.claytonlz.com/index.php/2009/10/make-fun-of-your-client/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:30:18 +0000</pubDate>
		<dc:creator>Clayton</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Riffs]]></category>
		<category><![CDATA[clients]]></category>
		<category><![CDATA[communication]]></category>

		<guid isPermaLink="false">http://www.claytonlz.com/?p=283</guid>
		<description><![CDATA[One thing I've always heard about learning a new language is that you can't consider yourself fully fluent until you can tell a joke. Telling a joke requires the understanding of homonyms and how words flow together. "So a guy walks into a bar..." sounds different than "A man enters beverage store...".

When dealing with clients, it's easy to joke about your client, but don't miss an opportunity to prevent future missteps once you know more about them.]]></description>
			<content:encoded><![CDATA[<p></p><p>One thing I&#8217;ve always heard about learning a new language is that you can&#8217;t consider yourself fully fluent until you can tell a joke. Telling a joke requires the understanding of homonyms and how words flow together. &#8220;So a guy walks into a bar&#8230;&#8221; sounds different than &#8220;A man enters beverage store&#8230;&#8221;.</p>

<p>When dealing with clients, it&#8217;s easy to joke about your client, but don&#8217;t miss an opportunity to prevent future missteps once you know more about them.</p>

<p>How often do you get off the phone with a client and immediately have a funny remark about some critique or issue they have mentioned. Typically this manifests itself when the client brings up an issue, that while important to them, is considered trivial by the developer.</p>

<blockquote>
Can you believe this guy!? I built out this whiz-bang feature and he&#8217;s just complaining about the font being too small!<br />
</blockquote>

<p>The key part of this interaction is that you&#8217;ve now got a little insight into what makes this particular client tick. When you demo the next few features and he is unimpressed by the functionality, but comments on the spacing of form elements you should skip the joke and make a mental note for the future.</p>

<p>Once you can tell a joke about your client, <em>before</em> the interaction, and you have an &#8220;I told ya so!&#8221; moment with yourself or your pair afterwards, you know you&#8217;ve made it to the next level of understanding that client. Now, the next time you deploy a feature, discuss requirements or ask a question you can preempt the inevitable by accounting for those quirks and personal preferences of your client.</p>

<p>Instead of making a joke, make them happy, then you can both smile. ;)</p>]]></content:encoded>
			<wfw:commentRss>http://www.claytonlz.com/index.php/2009/10/make-fun-of-your-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
