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.
<p>Here’s a working example from an app that I’m working on:</p>
stories/login
Story: registered user logs in As a registered user I want to have to log in So that only other registered users can see my dataScenario: 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.rb
require 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:
<ul>
<li>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!</li>
<li>run_story accepts arguments, including an options hash, which it will pass to the constructor of the PlainTextStoryRunner (in this case, :type => RailsStory)</li>
<li>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.</li>
<li>run_story … runs the story</li>
</ul>
<p>Keep your eyes peeled for more updates in the coming days.</p>



October 22nd, 2007 at 11:43 pm
David will you adopt me?
October 22nd, 2007 at 11:43 pm
Thanks again David. Works great!
require file end
October 22nd, 2007 at 11:43 pm
Andy: That’s a good suggestion, but it presents a couple of problems.
October 22nd, 2007 at 11:43 pm
hrm…in the case of AdminStepMatchers, I would think you should require login_step_matchers.rb (or whatever) inside the file that defines AdminStepMatchers
October 22nd, 2007 at 11:43 pm
Pat – good point.
October 22nd, 2007 at 11:43 pm
The story continues: In-browser editor for RSpec stories
October 22nd, 2007 at 11:43 pm
Realy awesome work !!!.