Plain Text Stories: Part III

October 25th, 2007

Here’s the latest update to Plain Text Stories. Effective r2789 in RSpec’s trunk.

<p>Step 1: Write a Story</p>

Story: simple addition

As an accountant I want to add numbers So that I can count beans

Scenario: add one plus one Given an addend of 1 And an addend of 1

When the addends are added

Then the sum should be 2
And the corks should be popped

Scenario: add two plus five Given an addend of 2 And an addend of 5

When the addends are added

Then the sum should be 7

Step 2: Create Steps

# This creates steps for :addition
steps_for(:addition) do
  Given("an addend of $addend") do |addend|
    @adder ||= Adder.new
    @adder << addend.to_i
  end
end

This appends to them

steps_for(:addition) do When("the addends are added") { @sum = @adder.sum } Then("the sum should be $sum") { |sum| @sum.should == sum.to_i } end

Step 3: Let her open the box … no, that’s not it …

<p>Step 3: Run the Story with the steps you want (adding any that are only for this story as you go).</p>

with_steps_for :addition do
  Then("the corks should be popped") {}
  run 'path/to/story/file'
end

Working with Rails?

with_steps_for :navigation do
  run 'path/to/story/file', :type => RailsStory
end

What about multiple groups of steps?


with_steps_for :login, :navigation, :form_submissions do
  run 'path/to/story/file'
end

Coming soon to a computer near you … (as soon as you can “seven up”)

5 Responses to “Plain Text Stories: Part III”

  1. Andy Watts Says:

    Very clean!

    <p>Thanks again.</p>
    
  2. Hendrik Says:

    I updated rspec to r2788 this morning and wondered why my update for rspec_on_rails yielded an incompatibilty error. The commit must have been right between my update commands. First, I stayed with r2788 but after reading this post I think r2789 is a big improvement for organizing the steps. I immediately refactored out all the common steps and can now include them using the new with_steps_for.

    <p>Thanks!</p>
    

    The “seven up” sounds familiar:

    <0> hvolkmer@faith:~$ alias | grep "svn up"
    alias 7up='svn up'
    

    ;-)

  3. nicholas a. evans Says:

    very nice!

  4. Andre Foeken Says:

    For a textmate language grammer and syntax higlighting for these wonderfull tests go here:http://www.movesonrails.com/

  5. Kerry Buckley Says:

    Excellent work! I’ve been playing with driving Selenium from the story runner.