【发布时间】:2014-08-27 17:19:03
【问题描述】:
我有一个 Rails 应用程序,如果没有用户登录,它会自动从主页重定向到登录页面。我使用 Authlogic 进行身份验证,使用 Cucumber 和 Capybara 进行测试。
我有以下场景:
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
但是当我运行 Cucumber 时,visit root_path 失败并显示 Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a controller object before creating objects
我做错了什么?
【问题讨论】:
-
您使用的是什么水豚驱动程序——默认的进程内 Rack::Test 驱动程序还是支持 Javascript 的驱动程序?
-
大概是默认的,因为我不知道有什么改变它。
-
那不是我想的支持 Javascript 的驱动程序的问题。嗯。
标签: ruby-on-rails-4 cucumber capybara authlogic