[rspec-users] simple story, extract link

Dan North tastapod at gmail.com
Wed Oct 3 08:25:16 EDT 2007


Hi Jonathan.

You can think of the What's in a Story article as trainer wheels. The point
is to start thinking in givens, events and outcomes (ie. which activities in
this scenario are setting up context, which are the "interesting bits" and
which are verification).

Once you are comfortable with this, it is perfectly natural to want multiple
steps interleaved. A very common pattern is to have some Givens then
repeating sequences of Whens and Thens, which represent various operations
through a user scenario. So you might say:

Given I am on the login screen

When I enter my credentials
Then I should be on the summaries page

When I select an entry
Then I should see its detail

When I delete the entry
Then I should be back on the summary page
And the deleted entry should have disappeared

As long as you are aware what each stanza represents ("I should be back on
the summary page" is an outcome, "I select an entry" is an event, etc.) then
you're definitely on the right lines.

I just found a paragraph from the article that might help:

"Not all scenarios are this simple. Some are best represented as a sequence
of events, described as: *given [some context] when [I do something] then
[this happens] when [I do another thing] then [this new thing happens]* and
so on. An example is a wizard-style website, where you step through a
sequence of screens to build up a complex data model. It is perfectly
appropriate to intermingle sequences of events and outcomes, as long as you
get into the habit of thinking in these terms."

Thanks,
Dan


On 10/3/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:
>
> Pat,
>
> Any more thoughts on submit_form and follow_link? I really like that
> idea, it fits well with the story concept, imo . And using the links
> and forms inside the response is better coverage than assuming the
> entry point to the next page.
>
> So a scenario becomes a sequence of actions taken by the user to
> accomplish a task (however small or large).
> In which case, could you have multiple When-Then's ? eg from your
> example
>
>
> >   Scenario "Successful listing" do
> >     Given "A user" do
> >       User.create! :login => "pat", :password => "password"
> >     end
> >     When "user visits the login page" do
> >       get "/login"
> >     end
>         Then "user sees login page" do
>            response.should have_text(/Please login/)
>         end
> >     When "user logs in" do
> >       submit_form :login, :login => "pat", :password => "password"
> >     end
>         Then "page shows Create an auction" do
>            response.should have_tag(...)
>        end
> >     When "user visits new auction page" do
> >       click_link "Create an auction"
> >     end
> >     When "user creates auction" do
> >       submit_form :auction, :auction => { :item_name => "Ruby for
> > Rails", :price => 50 }
> >     end
> >     Then "new auction should be listed" do
> >       response.should have_text(/Item successfully created!/)
> >       response.should have_text(/Ruby for Rails/)
> >     end
> >   end
>
>
> I realize this goes against http://dannorth.net/whats-in-a-story but
> it seems more correct than putting those actions into Given clauses.
>
>
> On Sep 25, 2007, at 6:48 PM, Pat Maddox wrote:
>
> > On 9/25/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> >> On 9/25/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:
> >>> hi,
> >>>
> >>> I just started fooling around with story runner, thought I'd start
> >>> with a dead simple scenario:
> >>> The first thing I do when describing a site to someone is go to the
> >>> home page, and begin exploring public pages from there.
> >>> So, that seems like a good first story to spec out.
> >>>
> >>> And I'd really like to extract the actual link from the rendered
> >>> page
> >>> (rather than just "assuming" in the spec), but I'm not sure how
> >>> to do
> >>> that
> >>> Something like:
> >>>
> >>>        # alink = find tag 'div#home-banner-links a '  where
> >>> content=="About"
> >>>        # url = extract the href attribute from alink
> >>>        get url
> >>>
> >>> Here's the story so far: http://pastie.caboo.se/100810
> >>
> >> Some comments:
> >>
> >> The second scenario seems more like the right level of abstraction
> >> than the first. Using "should render_template" in a Story seems too
> >> low level to me. What's interesting is what is being displayed, not
> >> what template is being used to display it.
> >
> > I see what you're getting at.  I've thought about it a bit myself, and
> > have decided that expecting a certain template is a pragmatic way of
> > knowing that the user is on the right page.
> >
> >
> >> The second scenario does a nicer job of that.
> >>
> >> One thing is that you won't be able to use the full URL. RailsStory
> >> wraps rails integration tests, which provide access to routing,
> >> but as
> >> paths, not URLs. So for href="http://0.0.0.0:3000/site_pages/about",
> >> you'd need to extract the "/site_pages/about" part and get that.
> >>
> >> Thoughts?
> >
> > I was planning on implementing a
> > click_link "Follow me!"
> >
> > sorta thing in the next couple days.  One problem I have is that right
> > now you still need to know too much about the underlying structure
> > (and golly if I didn't just contradict the first part of my reply!).
> > There was a thread a few days ago [1] where I hinted at that.  He
> > wanted to go directly to a URL, when he should have been following a
> > redirect.
> >
> > I think there needs to be some mechanism for following links /
> > submitting forms so that you can really follow the path a user takes.
> > That leaves you with something like:
> >
> > Story "Create an auction", %{
> >   As a seller
> >   I want to create a new auction
> >   So that I can get filthy rich
> > } do
> >
> >   Scenario "Successful listing" do
> >     Given "A user" do
> >       User.create! :login => "pat", :password => "password"
> >     end
> >     And "user visits the login page" do
> >       get "/login"
> >     end
> >     And "user logs in" do
> >       submit_form :login, :login => "pat", :password => "password"
> >     end
> >     And "user visits new auction page" do
> >       click_link "Create an auction"
> >     end
> >     When "user creates auction" do
> >       submit_form :auction, :auction => { :item_name => "Ruby for
> > Rails", :price => 50 }
> >     end
> >     Then "new auction should be listed" do
> >       response.should have_text(/Item successfully created!/)
> >       response.should have_text(/Ruby for Rails/)
> >     end
> >   end
> > end
> >
> > That requires you to know
> > 1. Point of entry
> > 2. IDs of forms and links (or text for links, if you prefer)
> > 3. The fields that a form uses
> >
> > So really all we've gotten away from is dependency on knowing certain
> > URLs, which I'm not positive is a huge benefit...otoh, this is closer
> > to tracing a user's path through the app which is nice.
> >
> > wdyt?
> >
> > Pat
> >
> > [1] http://rubyforge.org/pipermail/rspec-users/2007-September/
> > 003344.html
> > _______________________________________________
> > 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/20071003/a480df91/attachment-0001.html 


More information about the rspec-users mailing list