未定义的方法“setup” for main:Object 尝试使用 authlogic 运行控制器测试
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
安装方法未定义,因为它是 Test::Unit 方法。来自 authlogic 文档:
要对 RSpec 执行相同的操作,您必须包含 Authlogic::TestCase 并在每个规范之前调用 activate_authlogic:
The setup method is undefined because it's a Test::Unit method. From the authlogic docs:
To do the same thing with RSpec, you have to include Authlogic::TestCase and call activate_authlogic before each spec: