我的大多数测试都提出了以下问题,我不明白为什么.所有方法调用都会引发"身份验证"错误.我判断了代码是否有一个名为"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)>'

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

推荐答案

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

@Jeffeh你需要创建一个

再次感谢.

Ruby-on-rails相关问答推荐

在数组中定位不匹配的索引

将两个日期之间的差值转换为Ruby中的iso8601持续时间(如果需要,还可以使用Rails)

带有data-turbo的rails`link_to‘未获得turbo_stream请求格式

删除链接不起作用,重定向 echo 示 Ruby

Rails ActiveRecord::LogSubscriber 不输出详细查询日志(log)

Rails 7 中的预编译

Rails 7,Hotwire 动态表单,更新值不起作用

从 rails 5 迁移到 rails 6

Rails - 按连接表数据排序

未初始化的常量 ActionDispatch::Session::EncryptedCookieStore (NameError)

使用rails form_for时带有_path的未定义方法

File.open,写入和保存?

耙路由错误缺少:路由定义上的操作键

从 Rails 模型内部访问翻译文件 (i18n)

表单中的第一个参数不能包含 nil 或为空 - Rails 4

Ruby on Rails 3:通过 Rails 将数据流式传输到客户端

扩展 Devise SessionsController 以使用 JSON 进行身份验证

Sidekiq Rails 4.2 使用 Active Job 还是 Worker?有什么不同

如何在 Rails 3 中订购包含的元素

如何在 Rails 表单中将复选框和标签保持在同一行?