RSpec 控制器测试失败,Rails API - 未定义的方法“助手" [英] RSpec controller test failing with Rails API - Undefined Method 'helpers'

查看:32
本文介绍了RSpec 控制器测试失败,Rails API - 未定义的方法“助手"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照此 Rails API 指南 来更好地了解如何集成 RailsAPI 到我自己的应用程序中,但是我的 RSpec 测试在路由期望上失败了,我不知道为什么.

I'm trying to follow this Rails API Guide to better understand how to integrate the Rails API into my own application, however my RSpec test is failing on the routing expectation and I'm not sure why.

我的错误信息是

1) Api::V1::UsersController POST #create when is not created renders an errors json
     Failure/Error: expect(user_response).to have_key(:errors)
     NoMethodError:
     undefined method "helpers" for #   <ActionDispatch::Routing::RouteSet::NamedRouteCollection:0x007f7f8a1c0938>
       Did you mean?  helper_names
     # ./spec/controllers/api/v1/users_controller_spec.rb:47:in <block (4 levels) in top (required)>'

我认为链接这个 Gist 可能为了发布代码更方便.如果直接在我的帖子上发布纯文本是首选,我深表歉意.我刚开始发帖^^

I think linking this Gist might be more convenient for the sake of posting code. I apologize if posting plaintext directly on my post is preferred. I'm new to posting ^^

推荐答案

我也在使用 Rails 5 并升级到rspec-rails",~> 3.5"似乎已经成功了!谢谢

I am also using Rails 5 and upgrading to "rspec-rails", "~> 3.5" seems to have done the trick! thanks

这篇关于RSpec 控制器测试失败,Rails API - 未定义的方法“助手"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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