[rspec-users] StoryRunner docs/guidance

Andrew WC Brown omen.king at gmail.com
Sat Dec 22 19:25:55 EST 2007


I never really thought of placing subdirectories in the stories directory.
I guess that would be useful for separating your administrative stories for
the back end of your app.

I named my stories in the following convention:

#role#_#action#_story.rb

eg:
user_creates_project_story.rb
user_edits_project_story.rb
user_deletes_project_story.rb
user_views_project_story.rb


On Dec 21, 2007 6:40 PM, Jonathan Linowes <jonathan at parkerhill.com> wrote:

> I just went through this myself yesterday, and was considering
> posting an article on my blog, but figured it'd be too short lived,
> once the doc page is up on the rspec site. So I'll post here what
> I've cobbled together from various other articles, emails, and
> generous help on #rspec.
>
> 1. DECIDE A DIRECTORY STRUCTURE AND FILL OUT helper.rb
> Directory structure:
> stories/
> stories/steps/
> stories/stories/
> stories/stories/foo
> stories/stories/foo/a_foo_story
> stories/stories/foo/a_foo_story.rb
> stories/stories/foo/another_foo_story
> stories/stories/foo/another_foo_story.rb
> stories/all.rb
> stories/helper.rb
>
> File: stories/helper.rb:
>
> ENV["RAILS_ENV"] = "test"
> require File.expand_path(File.dirname(__FILE__) + "/../config/
> environment")
> require 'spec/rails/story_adapter'
>
> Dir['stories/steps/**/*.rb'].each do |steps_file|
>   require steps_file
> end
>
> # add extra include's and helper methods here
> include FixtureReplacement
>
>
> 2. WRITE A SHORT TEXT STORY
>
> File: stories/stories/admin/admin_accounts
>
> Story: admin user manages accounts
>   As an admin user
>   I want site-wide access to accounts, projects, and users
>   So I can create and modify items
>
>   Scenario: admin user logs in
>     Given an admin user and account
>     And a bunch of accounts setup
>     When user logs in with  email: admin at example.com and password:
> secret
>     Then browser should show the Admin page
>     And browser should show the Accounts table
>
>
> 3. WRITE A rb SCRIPT FOR THE STORY
>
> File: stories/stories/admin/admin_accounts.rb
>
> require File.join(File.dirname(__FILE__), "../../helper")
>
> with_steps_for :misc do
>   run File.expand_path(__FILE__).gsub(".rb",""), :type => RailsStory
> end
>
> For other stories, just copy this file, and add/change the steps
> groups as required. The rest of the file is unchanged (it gets the
> text story filename from its own name.)
>
>
> 3.A And Run It:
>
>        $ ruby stories/stories/admin/admin_accounts.rb
>
> should show 1 scenarios: 0 succeeded, 0 failed, 1 pending
>
>
> 4. CODE THE STEPS
> To start, I put all my steps into a "miscellaneous" steps file until
> patterns emerge when I'll separate them out into different steps files
>
> File: stores/steps/misc_steps.rb
>
> steps_for(:misc) do
>   Given "an admin user and account" do
>     @user = create_user( :email => "admin at example.com", :password =>
> 'secret', :site_admin => true)
>   end
>
>   Given "a bunch of accounts setup" do
>     4.times do
>       create_account
>     end
>   end
>
>   When "user logs in with email: $email and password: $password" do |
> email, password|
>     post_via_redirect "/sessions", :email => email, :password =>
> password, :account => account
>     response.should be_success
>      session[:user].should == @user.id     # should_be_logged_in(@user)
>   end
>
>   Then "browser should show the $h1_contents page" do |h1_contents|
>     response.should have_tag("h1", h1_contents)
>   end
>
>   Then "browser should show the $table_name table" do |table_name|
>     response.should have_tag("div h2", table_name)
>   end
> end
>
> 4.A And Run It
>
>        $ ruby stories/stories/admin/admin_accounts.rb
> or
>        $ ruby stories/all.rb
>
>
>
>
> --linoj
>
>
>
>
>
> On Dec 21, 2007, at 2:59 PM, Jonathan Leighton wrote:
>
> > Hi all,
> >
> > Are there any plans for better documentation for the new StoryRunner
> > feature? I tried to use it today (with Rails), and had a hard time
> > getting my head around whether I was doing it "right" and exactly what
> > things are appropriate to test at that level (this might be
> > exacerbated
> > by the fact that I've never really used integration testing that
> > much).
> > A full example of testing a Rails controller would be extremely useful
> > to me.
> >
> > Thanks,
> >
> > Jon
> >
> > --
> > Jonathan Leighton, Web Developer
> > http://jonathanleighton.com/
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071222/807d5f9b/attachment.html 


More information about the rspec-users mailing list