通过authlogic登录,而不必每次都填写表单 [英] Log-in through authlogic without having to fill in form every time
问题描述
这些方案大多数以我已登录为开头 步。目前我的实现是:
访问path_to('登录页面')
/ pre>
fill_in :with =>'user')
fill_in('Password',:with =>'password')
click_button('Login')
这很好,但是在每一个场景之前加载和提交登录表单变得很费时。
有没有办法在这个步骤中简单地设置会话,而不必每次都通过表单。
解决方案稍微晚一点,但这对我来说在Rails 3.0.10。
在
功能/支持/authlogic.rb
:requireauthlogic / test_case
World(Authlogic: :TestCase)
ApplicationController.skip_before_filter:activate_authlogic
before do
activate_authlogic
end
然后在
features / step_definitions / user_sessions_steps.rb
给定/ ^我已经登录$ / do
/ pre>
UserSession.create!(User.find_by_name!('user'))
end
显然,如果要登录特定用户,您可以将用户名传递给步骤定义。
完整的详细信息在本博文: http://laserlemon.com/blog/2011/05/20/make-authlogic-and-cucumber-play-nice/
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/
这篇关于通过authlogic登录,而不必每次都填写表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!