Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log-in through authlogic without having to fill in form every time

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?

like image 708
AlistairH Avatar asked Sep 02 '10 16:09

AlistairH


1 Answers

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/

like image 88
PhilT Avatar answered Nov 22 '22 18:11

PhilT