未定义的方法“setup” for main:Object 尝试使用 authlogic 运行控制器测试

发布于 2024-11-05 20:15:36 字数 955 浏览 1 评论 0原文

我对 RSpec 测试有点陌生,我正在尝试使用 RSpec 2 和 Authlogic 3 身份验证在我的 Rails 3 应用程序中运行一些控制器测试。

按照 Authlogic 文档提供的步骤 (http://rdoc.info/github/binarylogic /authlogic/master/Authlogic/TestCase),我的文件中包含以下代码:

spec_helper.rb

require "authlogic/test_case" # include at the top of test_helper.rb  

events_controller_spec.rb

require 'spec_helper'  
setup :activate_authlogic  

正在运行通过 rake spec SPEC='spec/controllers/eventos_controller_spec.rb' 进行的测试我收到以下错误:

events_controller_spec.rb:2: undefined method `setup' for main:Object (NoMethodError)

当我在使用 authlogic 之前运行测试时,我没有遇到任何问题。

我正在使用 Ubuntu 11.04 和以下配置:

ruby - 1.8.7  
rails - 3.0.7  
authlogic - 3.0.2  
rspec-rails - 2.4.1  
factory_girl_rails - 1.0.1

I am a little new to RSpec tests and i am trying to run some controller tests in my Rails 3 application using RSpec 2 and Authlogic 3 authentication.

Following the steps provided by Authlogic documentation (http://rdoc.info/github/binarylogic/authlogic/master/Authlogic/TestCase), i got the following codes in my files:

spec_helper.rb

require "authlogic/test_case" # include at the top of test_helper.rb  

events_controller_spec.rb

require 'spec_helper'  
setup :activate_authlogic  

Running the tests through rake spec SPEC='spec/controllers/eventos_controller_spec.rb' i got the following error:

events_controller_spec.rb:2: undefined method `setup' for main:Object (NoMethodError)

When i ran the tests before using authlogic i've got no problems.

I am using Ubuntu 11.04 and this configuration:

ruby - 1.8.7  
rails - 3.0.7  
authlogic - 3.0.2  
rspec-rails - 2.4.1  
factory_girl_rails - 1.0.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睡美人的小仙女 2024-11-12 20:15:36

安装方法未定义,因为它是 Test::Unit 方法。来自 authlogic 文档

如果您使用的是 Test::Unit::TestCase(Ruby 附带的标准测试库),那么您可以跳过下一部分。如果不是,您需要将 Authlogic::TestCase 包含到您的测试套件中。

要对 RSpec 执行相同的操作,您必须包含 Authlogic::TestCase 并在每个规范之前调用 activate_authlogic:

require 'spec_helper'

describe EventsController do
  include Authlogic::TestCase

  before(:each) do
    activate_authlogic
  end
end

The setup method is undefined because it's a Test::Unit method. From the authlogic docs:

If you are using Test::Unit::TestCase, the standard testing library that comes with ruby, then you can skip this next part. If you are not, you need to include the Authlogic::TestCase into your testing suite.

To do the same thing with RSpec, you have to include Authlogic::TestCase and call activate_authlogic before each spec:

require 'spec_helper'

describe EventsController do
  include Authlogic::TestCase

  before(:each) do
    activate_authlogic
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文