Ruby测试时一直出现“undefined method”错误怎么办?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (106)

我的大多数测试都在下面:

  1) Admin::CommentsController handling GET to index is successful
     Failure/Error: get :index
     undefined method `authenticate!' for nil:NilClass
     # ./spec/controllers/admin/comments_controller_spec.rb:9:in `block (3 levels) in <top (required)>'


  124) PostsController handling GET for a single post should render show template
     Failure/Error: get :show, :year => '2008', :month => '01', :day => '01', :slug => 'a-post'
     undefined method `authenticate' for nil:NilClass
     # ./app/controllers/application_controller.rb:18:in `set_current_user_for_model'
     # ./spec/controllers/posts_controller_spec.rb:131:in `do_get'
     # ./spec/controllers/posts_controller_spec.rb:140:in `block (3 levels) in <top (required)>'

可以在那里找到=>github.com/agilepandas/enki

提问于
用户回答回答于
用户回答回答于

我知道你正在使用Rspec,但你遇到同样的问题Test::Unit。只需要添加设计测试助手test/test_helper.rb

class ActiveSupport::TestCase
  include Devise::TestHelpers
end

扫码关注云+社区