[rspec-users] Persisting Logins and Sessions across scenarios

James Byrne lists at ruby-forum.com
Mon Jan 12 12:46:23 EST 2009

David Chelimsky wrote:

> 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
> end
> 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
> HTH,
> David

Thanks David, I have something like that:

When /user named "(.*)" logs in/ do |name|
  # assumes that the user given exists of course
  visits root_path
  UserSession.find.destroy if UserSession.find
  Then "enter the username \"#{name}\""
  Then "enter the password \"#{name}-password\""
  Then "press the login button"
  Then "welcome message"

But this seems needlessly expensive given that the entire application is 
secured.  Is there no way of preserving a login session for any 
arbitrary period across both features and scenario?  Is there a 
technical or philosophical reason why this is not so?

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list