Plain Text Stories: Part III 5

Posted by David Thu, 25 Oct 2007 08:52:20 GMT

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

Step 1: Write a Story

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 …

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

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”)

Comments

Leave a response

  1. Avatar
    Andy Watts Thu, 25 Oct 2007 12:49:19 GMT

    Very clean!

    Thanks again.

  2. Avatar
    Hendrik Thu, 25 Oct 2007 16:15:05 GMT

    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.

    Thanks!

    The “seven up” sounds familiar:
    <0> hvolkmer@faith:~$ alias | grep "svn up" 
    alias 7up='svn up'
    

    ;-)

  3. Avatar
    nicholas a. evans Sun, 28 Oct 2007 16:13:18 GMT

    very nice!

  4. Avatar
    Andre Foeken Tue, 06 Nov 2007 16:04:16 GMT

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

  5. Avatar
    Kerry Buckley Wed, 07 Nov 2007 13:12:57 GMT

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

Comments