Rspec 3. 未定义的局部变量或方法`response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90> [英] Rspec 3. undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>
本文介绍了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 #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文