[rspec-users] Persisting Logins and Sessions across scenarios
dchelimsky at gmail.com
Mon Jan 12 12:21:49 EST 2009
On Mon, Jan 12, 2009 at 10:45 AM, James Byrne <lists at ruby-forum.com> wrote:
> I have an authentication filter on my application controller. I have the
> following feature statements:
> Scenario: I should be logged in to do any of this
> Given we have a user named "myuser"
> And the user named "myuser" logs in
> When they visit the "entities" page
> Then they should see the "entities" page
> Scenario: Entity should have essential identification information
> Given I do not have any entities
> And I am on the add a new entity page
> When I enter "My Business Relation" in the "Common Name" field
> And I enter "My B.R. Legal Name" in the "Legal Name" field
> And I choose "Corporation" as the "Legal Form"
> And I press "Create"
> Then I should save the entity information successfully
> In scenario 1, the user is logged in successfully and the response body
> after the 'see the "entities" page' is indeed the entities/index page.
> When /should see the "(entities)" page/ do |resource|
> response.body.should =~ /All Entities/m
> When /on the add a new entity page/ do
> visits new_entity_path
> response.body.should =~ /Add a New Entity/m
> However, in Scenario 2, I am assuming that a.) the same user (myuser)
> and their associated login session is employed. Since the response body
> from this is the login page then evidently this assumption is wrong and
> something else is going on. Can some inform me as to how test logins
> are managed/maintained/reused within cucumber/webrat?
Each scenario operates in a new session.
I usually have a step that aggregates the login process:
Given /^I am logged in as "(.*)"/ do |role|
#create a user whose name and role are based on the role
#log in that user
This lets me say:
Given I am logged in as "admin"
When I visit the super-secret page
Then I see it and learn about all its mystery
More information about the rspec-users