[rspec-users] Plain Text Stories Chaining Scenarios

Dan North tastapod at gmail.com
Thu Nov 15 15:04:24 EST 2007


Hi Nathan.

You can reuse a scenario as a given in another scenario:

Scenario "passing go"
  Given "I am not in jail"
  When "I pass go"
  Then "I collect $200"

Scenario "landing on someone's hotel after passing go"
*  GivenScenario* "passing go"  *# matches the scenario name*
  When "I land on someone's hotel"
  Then "I receive the $200 before I have to pay out for the hotel"


For the second scenario, the story runner reruns the whole first scenario
and keeps the same object instance for running the remaining steps. This
means that any state you set up (@variables, mixins, etc.) are available for
the other steps. It's useful for incrementally building up something like a
workflow or a state engine.

Cheers,
Dan

On Nov 15, 2007 3:01 AM, Nathan Sutton <fowlduck at gmail.com> wrote:

> I'm writing a plain text story (testing the waters) and I have
> scenarios that I need to chain in my specs.
>
> Here is what I have so far:
>
> Story: User purchasing tshirts
>   As a user
>   I want to checkout
>   So that I can purchase shirts
>
>   Scenario: User goes to checkout with nothing in cart
>     Given a user
>     And user has an empty cart
>     When user goes to checkout
>     Then user should see the page: site index
>     And page should include the text: you have nothing in your cart
>
>   Scenario: Logged-in user goes to checkout
>     Given a logged-in user
>     And user has a cart with items in it
>     When user goes to checkout
>     Then user should see the page: address entry
>
>   Scenario: Anonymous user goes to checkout
>     Given an anonymous user
>     And user has a cart with items in it
>     When user goes to checkout
>     Then user should see the who are you page
>
>   Scenario: Anonymous user continues as guest from 'who are you' page
>     Given an anonymous user
>     And user has a cart with items in it
>     And user is at the page: who are you
>     When user continues as a guest
>     Then user should see the page: address entry
>     And page should include the text: guest
>
>   Scenario: Anonymous user decides to sign-up at 'who are you' page
>     Given an anonymous user
>     And user has a cart with items in it
>     And user is at the page: who are you
>     When user goes to sign-up
>     Then user should see the page: sign-up
>
>   Scenario: Registered user decides to login at 'who are you' page
>     Given an anonymous user
>     And user has a cart with items in it
>
>     And user is at the page: who are you
>     When user goes to login
>     Then user should see the page: login
>
>   Scenario: Registered user logs in and is returned to checkout
>     Given an anonymous user
>     And user has a cart with items in it
>     and user is at the page: login
>     When user logs in
>     Then user should see the page: address entry
>
>   Scenario: Anonymous user signs-up and is returned to checkout
>     Given an anonymous user
>     And user has a cart with items in it
>     And user is at the page: sign-up
>     When user signs-up
>     Then user should see the page: address entry
>
> The parts that I need to chain are the last four scenarios.  I want to
> make sure that when they leave to signup and log in that they're
> returned to the next step in checkout.  How would I go about doing
> this in the stories?  Would that just be another given?
>
> Also, how do the rest look, sane?
>
> Thanks,
>
> Nate
> _______________________________________________
> 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/20071115/ee4e84a8/attachment.html 


More information about the rspec-users mailing list