[rspec-users] Cucumber speed tips

Luke Melia luke at lukemelia.com
Sat Jan 3 22:36:54 EST 2009

On Jan 3, 2009, at 9:12 PM, Ben Mabey wrote:

> The downside with this approach is that it only works with the rails  
> webrat adapter.  One solution which I have been meaning to do is to  
> create a UsersSessionManager.  The manager would be responsible for  
> logging in all the various roles you use in your app with different  
> webrat sessions (and then caching them.)  You could then swap out  
> which session you would be using in your steps...
> So you could then do something like:
> logged_in_as 'Admin' do |session|
> session.click_link 'Foo'
> ...
> end
> Or..
> Given /^I am logged in as an '(.+)'$/ |role|
>  login_as role
> end
> The 'login_as' would swap out the session that the World object uses  
> so the next steps would be using the appropriate session.

In general I like the idea, Ben. At weplay, we use webrat to drive  
rails and selenium, and logged_in_as method has the following  
implementation in the Selenium world:

   def logged_in_as(user)
     visit login_for_test_path(user)

where login_for_test_path is is a named route defined only for the  
selenium environment that provides a "quick" login of a given user.

Would the solution you're thinking of help with this? I'm not sure how  
you would "cache" a selenium session.

Luke Melia
luke at lukemelia.com

More information about the rspec-users mailing list