【问题标题】:Authlogic activation in CucumberCucumber 中的 Authlogic 激活
【发布时间】: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


【解决方案1】:

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

对我有帮助的是删除行 World(Authlogic::TestCase)ApplicationController.skip_before_filter :activate_authlogic 并仅将其保留在 support/authlogic.rb 中:

require "authlogic/test_case"

Before do
  activate_authlogic
end

找到了这个解决方案here。目前有效,我稍后会检查是否有任何副作用。

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2021-10-26
    • 1970-01-01
    相关资源
    最近更新 更多