On Dec 27, 2008, at 3:08 AM, Mischa Fierer wrote:
You only need to test login for each login case, not for each time
you are testing some sort of logged in functionality.
In most cases you can just post to sessions/create rather than
filling in a login form.
I also wanted to speed up the "Given I am a logged in user" type of
thing, as you suggested, but took a different, faster approach which
may also work for you. I set a cookie to auto-login the user on the
next request. Implementation as a gist http://gist.github.com/42973
and below. -Luke
features/steps/users_steps.rb:
Given "I'm a logged in member" do
@me = create_adult
logged_in_as @me
end
features/support/env.rb:
class Cucumber::Rails::World
...
def logged_in_as(user)
cookies['integration_test_user'] = user.id.to_s
end
,,,
end
app/controllers/application.rb
class ApplicationController < ActionController::Base
...
before_filter :login_integration_test_user, :if => lambda
{ Rails.env == 'test' }
...
def login_integration_test_user
return true if cookies['integration_test_user'].blank?
integration_test_user_id = cookies['integration_test_user'].to_i
if integration_test_user_id != current_user.id
reset_session
self.current_user = User.find(integration_test_user_id)
end
cookies['integration_test_user'] = nil
end
--
Luke Melia
l...@lukemelia.com
http://www.lukemelia.com/
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users