I have a number of Cucumber scenarios which run with capybara on a project I am working on.
Most of these scenarios start with a "Given I am logged in" step. Currently my implementation of this is:
visit path_to('the login page')
fill_in('Username', :with => 'user')
fill_in('Password', :with => 'password')
click_button('Login')
This works fine, however it is becoming a bit time consuming having to load and submit the login form before every single scenario.
Is there a way to simply set up the session in this step without having to go through the form every single time?
A bit late to the show as usual but this works for me on Rails 3.0.10.
In features/support/authlogic.rb
:
require "authlogic/test_case"
World(Authlogic::TestCase)
ApplicationController.skip_before_filter :activate_authlogic
Before do
activate_authlogic
end
Then in features/step_definitions/user_sessions_steps.rb
Given /^I am already logged in$/ do
UserSession.create!(User.find_by_name!('user'))
end
Obviously, you can pass a username into the step definition if you want to login a specific user.
Full details are in this blog post: http://laserlemon.com/blog/2011/05/20/make-authlogic-and-cucumber-play-nice/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With