Plain Text Stories on Rails
October 22nd, 2007
Since my last post on plain text stories, there have already been a few improvements, not the least of which is that it will now work with Rails. Again, this is trunk (rev 2769+) only and experimental.
Here’s a working example from an app that I’m working on:
stories/loginStory: registered user logs in
As a registered user
I want to have to log in
So that only other registered users can see my data
Scenario: user logs in and sees welcome page
Given a user registered with login: foo and password: test
When user logs in with login: foo and password: test
Then user should see the welcome page
Scenario: user logs in with wrong password
Given a user registered with login: foo and password: test
When user logs in with login: foo and password: wrong
Then user should see the login form
And page should include text: There was an error logging in.
Scenario: user logs in with wrong login name
Given a user registered with login: foo and password: test
When user logs in with login: wrong and password: test
Then user should see the login form
And page should include text: There was an error logging in.
[Update: modified to use runner.steps instead of runner.step_matchers]
stories/login.rbrequire File.join(File.dirname(__FILE__), *%w[helper])
run_story :type => RailsStory do |runner|
runner.steps << LoginSteps.new
runner.steps << NavigationSteps.new
runner.load File.expand_path(__FILE__).gsub(".rb","")
end
Here’s what’s new in this example:
- run_story is added to the main object so you don’t have to remember that silly path to the PlainTextStoryRunner which will undoutedbly change!
- run_story accepts arguments, including an options hash, which it will pass to the constructor of the PlainTextStoryRunner (in this case, :type => RailsStory)
- run_story yields the runner, which now supports a load method which you use to tell it where to find the plain text story file.
- run_story … runs the story
Keep your eyes peeled for more updates in the coming days.
7 Responses to “Plain Text Stories on Rails”
Sorry, comments are closed for this article.


July 13th, 2008 at 06:06 AM
David will you adopt me?
July 13th, 2008 at 06:06 AM
Thanks again David. Works great!
Minor gotcha. For requiring the step libraries, I added the following to my stories/helper.rb
Should ‘ruby script/generate rspec’ do this?
July 13th, 2008 at 06:06 AM
Andy: That’s a good suggestion, but it presents a couple of problems.
For one, it imposes a convention of calling the subdirectory steps (really, they are step_matchers) and assuming that it is flat. I’m using step_matchers and I’m already playing w/ directory hierarchies below that.
So we definitely wouldn’t want to do this until a convention emerges definitively.
Even then, there’s another, more substantial problem: because you can create hierarchies of StepMatchers (which I’ve been doing with some success – admittedly only for a day, but success none-the-less), load order is meaningful. As soon as AdminStepMatchers extends LoginStepMatchers, we need to ensure that LoginStepMatchers loads first.
July 13th, 2008 at 06:06 AM
hrm…in the case of AdminStepMatchers, I would think you should require login_step_matchers.rb (or whatever) inside the file that defines AdminStepMatchers
July 13th, 2008 at 06:06 AM
Pat – good point.
July 13th, 2008 at 06:06 AM
The story continues: In-browser editor for RSpec stories
July 13th, 2008 at 06:06 AM
Realy awesome work !!!.
Does the new plain text story funktion in trunk support other languanges than english ?