所有 Ruby 测试引发:未定义的方法“验证"为 nil:NilClass [英] All Ruby tests raising: undefined method `authenticate' for nil:NilClass

查看:14
本文介绍了所有 Ruby 测试引发:未定义的方法“验证"为 nil:NilClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的大多数测试都提出以下问题,我不明白为什么.所有方法调用都会引发身份验证"错误.我已经检查了代码是否有一种称为身份验证"的方法,但没有这种方法.

Most of my tests are raising the following and I don't understand why. All methods call raise the 'authenticate' error. I've checked the code if there was a method called "authenticate" but there is no such method.

  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如果您想自己运行测试.

The project can be found over there => https://github.com/agilepandas/enki in case you'd like to run the tests your self.

推荐答案

此问题已由 @MatthewClosson 在 Twitter 上回答

This question has been answered on Twitter by @MatthewClosson

@jeffehh 你需要创建一个spec/support/devise.rb 文件为此处指定 https://github.com/plataformatec/devise#test-helpers包括设计测试助手#ruby

@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 测试引发:未定义的方法“验证"为 nil:NilClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆