2014-08-27 44 views
1

我有一个Rails应用程序,如果没有用户登录,它会自动从主页重定向到登录页面。我使用Authlogic进行身份验证,Cucumber和Capybara进行测试。Cucumber中的Authlogic激活

我有以下情形:

Scenario: Start application 
    Given I am not logged in 
    When I go to the application web page 
    Then I should see a login form 

用下面的测试步骤:

Given(/^I am not logged in$/) do 
end 


When(/^I go to the application web page$/) do 
    visit root_path 
end 

Then I should see a login form是有点复杂,因为它的通配符,但我没有得到那么远,因此可能无所谓)。

http://laserlemon.com/blog/2011/05/20/make-authlogic-and-cucumber-play-nice/指导我已经创建了一个包含文件features\support\authlogic,rb

require 'authlogic/test_case' 

World(Authlogic::TestCase) 

ApplicationController.skip_before_filter :activate_authlogic 

Before do 
    activate_authlogic 
end 

但是当我运行黄瓜,visit root_path失败Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a controller object before creating objects

我在做什么错?

+0

您使用的是什么水豚驱动程序 - 默认的进程内Rack :: Test驱动程序或支持Javascript的驱动程序? – 2014-08-28 05:56:41

+0

大概是默认的一个,因为我没有意识到已经做了任何改变它。 – digitig 2014-08-28 08:57:54

+0

不是我想到的支持Javascript的驱动程序的问题。嗯。 – 2014-08-29 00:29:37

回答

0

我一直在使用完全相同的代码与rails3,今天我发现完全相同的错误Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a controller object before creating objects当我试图用rails4运行我的黄瓜测试。

什么帮助我是去除线World(Authlogic::TestCase)ApplicationController.skip_before_filter :activate_authlogic,仅此保持support/authlogic.rb

require "authlogic/test_case" 

Before do 
    activate_authlogic 
end 

发现这个解决方案here。现在,它的工作原理,我会稍后检查是否有任何副作用。