Plain Text Stories: Part III
October 24th, 2007
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”)
5 Responses to “Plain Text Stories: Part III”
Sorry, comments are closed for this article.


July 13th, 2008 at 06:06 AM
Very clean!
Thanks again.
July 13th, 2008 at 06:06 AM
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:;-)
July 13th, 2008 at 06:06 AM
very nice!
July 13th, 2008 at 06:06 AM
For a textmate language grammer and syntax higlighting for these wonderfull tests go here:http://www.movesonrails.com/
July 13th, 2008 at 06:06 AM
Excellent work! I’ve been playing with driving Selenium from the story runner.