[rspec-users] RSpec stories introduction

James B. Byrne byrnejb at harte-lyne.ca
Mon Jan 14 15:55:36 EST 2008

I have played a bit with RSpec specs and now want to check out stories.  I
note that there is no generator for rspec stories pre se (unless I managed
to miss all references to one ) and that the only directory relating to
stories added by installing rspec is ./stories itself.

The documentation at rspec.info seems to presume a great deal of prior
knowledge. What I am looking for is a guided tour of what should go where
and how each file should be called to implement stories.

For the moment I have placed everything in ./stories, although I am nearly
certain that this is not the way to go.

I have created a file called "new_job.txt" in ./stories that contains this:

Story: open a new job
  As an authorized user
  I want to open a new job
  So that I can do work
  For a client

  Scenario: client is active
    Given client exists in database
    And client status is active
    When I add a new job
    Then a job number is automatically assigned
    And a job_parties entry is added for job and client with type "bill"
    And job_parties status is set to "quote"

  Scenario: client is held for administrative approval

I infer that I should also create a file called new_job.rb in stories and
that it should contain:

with_steps_for :new_jobs_steps do
  run './new_job.txt'

Then I believe that I require yet another file called "new_job_steps.rb"
that has code that looks somewhat like this:

steps_for(:new_job_steps) do
  Given "client exists in database" do
    Client.destroy_all "short_name == 'test client exists'"
    Client.create!(:short_name => 'test client exists',
                   :status => 'active')

and at this point I am lost.  Do I really need more than one step file,
say one or more to create the test client with the necessary attributes
and another to add the job and perhaps a third to create an authorized
user login?  Does that mean that new_job.rb should look like this:

with_steps_for :login, :client_active, :new_jobs_steps do
  run './new_job.txt'

Can someone show me how they would wire this together? and with what
directories and file names that they would use?  I am having a deal of
trouble getting my head wrapped around this approach.

***          E-Mail is NOT a SECURE channel          ***
James B. Byrne                mailto:ByrneJB at Harte-Lyne.ca
Harte & Lyne Limited          http://www.harte-lyne.ca
9 Brockley Drive              vox: +1 905 561 1241
Hamilton, Ontario             fax: +1 905 561 0757
Canada  L8E 3C3

More information about the rspec-users mailing list