ruby-on-rails - 所有 Ruby 测试都引发 : undefined method `authenticate' for nil:NilClass

标签 ruby-on-rails ruby testing rspec devise

我的大部分测试都引发了以下问题,我不明白为什么。所有方法调用都会引发“验证”错误。我检查了代码是否有一个名为“authenticate”的方法,但没有这样的方法。

  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)>'

项目可以在那边找到=> https://github.com/agilepandas/enki如果您想自己运行测试。

最佳答案

@MatthewClosson 在 Twitter 上回答了这个问题

@jeffehh You need to create a spec/support/devise.rb file as specified here https://github.com/plataformatec/devise#test-helpers to include the devise test helpers #ruby

再次感谢。

关于ruby-on-rails - 所有 Ruby 测试都引发 : undefined method `authenticate' for nil:NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4308094/

相关文章:

ios - 在 iOS 上重置 "<App> would like to access your photos"对话框

ruby-on-rails - 我修复了一个失败的 rails 迁移,但为什么这个修复有效?

sql - 如何获得可链接的标签?

ruby - 瘦找不到 pg_ext

ruby-on-rails - 计算两个 Time 对象之间的时间差

javascript - sinon - 如何检查一个值是否在数组中?

ruby-on-rails - Rails 3 中的简单 Facebook API 使用

ruby-on-rails - Rails acts_as_taggable heroku 500 错误

ruby-on-rails - Define_method block 中的条件代码

android - 无需编译即可制作具有唯一ID的APK