[rspec-users] simple story, extract link

Jonathan Linowes jonathan at parkerhill.com
Tue Sep 25 19:12:25 EDT 2007


yep, in my case I'm imagining a next scenario may go something like  
this:
- from home page, click on Contact Us,
see contact form, fill out fields,
submit form, see thank you page,
email sent to admin


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



More information about the rspec-users mailing list