Rspec 3. 未定义的局部变量或方法`response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007

编程入门 行业动态 更新时间:2024-10-11 17:23:58
本文介绍了Rspec 3. 未定义的局部变量或方法`response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用 rspec 测试 API 控制器.所以这是一段简单的代码:

I want to test API controller with rspec. So here is the simple piece of code:

require 'rails_helper' describe "GET /api/config" do it 'routes GET to /api/config to Api::V1::ConfigsController#show' do get '/api/config.json' expect(response).to be_success end end

但是我有一个错误:

1) Configs API GET /api/config routes GET to /api/config to Api::V1::ConfigsController#show Failure/Error: expect(response).to be_success NameError: undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90> # ./spec/routing/api/v1/devise/configs_routing_spec.rb:13:in `block (3 levels) in <top (required)>'

推荐答案

在 RSpec 3 中,你会这样做:

In RSpec 3 you would do:

get '/api/config.json' expect(response.status).to be(200)

您缺少的是 describe 块中的类型声明,即:

What you're missing is a type declaration in your describe block, ie:

describe "GET /api/config", type: :controller do end

更多推荐

Rspec 3. 未定义的局部变量或方法`response' for #&lt;RSpec::ExampleGroups::ConfigsAPI

本文发布于:2023-10-27 23:42:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   局部   未定义   方法   response

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!