*** RuntimeError 异常:ActionView::Helpers::ControllerHelper#response 委托给 controller.response,但控制器为零 [英] *** RuntimeError Exception: ActionView::Helpers::ControllerHelper#response delegated to controller.response, but controller is nil

查看:26
本文介绍了*** RuntimeError 异常:ActionView::Helpers::ControllerHelper#response 委托给 controller.response,但控制器为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试为端点运行我的 api 规范时遇到了一个问题.当我运行规范并检查响应时,它说:

I'm running into an issue when I try to run my api specs for an endpoint. When I run the spec and check the response it says:

*** RuntimeError Exception: ActionView::Helpers::ControllerHelper#response delegated to controller.response, but controller is nil: #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007faeb4852b08

我在 controllers/api/v1/catalog_controller.rb

class Api::V1::CatalogController < ApplicationController
  def search
    ...some stuff here...
    render json: {some_response}
  end
end

它的匹配规范位于spec/controllers/api/v1/catalog_controller_spec.rb

describe Api::V1::CatalogController do
  describe "searching" do
    before(:all) do
      @title = FactoryGirl.create(:title, {name: "Test Title"})
      @author = FactoryGirl.create(:author, last_name: "Smith")
      @edition = FactoryGirl.create(:edition, title: @title, writer_id: @author.id)
    end
    context "#search" do
      it "should return the given titles for a single word search" do
        get :search, {search_terms: {term: 'smith'}}
        expect(response).status.to eql(200)
        return_value.body.should == {titles: [@title]}
      end
    end
  end
end

知道我做错了什么吗?

推荐答案

我已通过删除该行来解决该问题

I've resolved the issue by removing the line

 config.include ActionView::Helpers

来自我的 spec_helper.rb 配置块.我猜这是矛盾的.我不太确定为什么那么进一步的洞察力会很棒.

from my spec_helper.rb config block. I guess it was conflicting. I'm not terribly sure why so any further insight would be awesome.

这篇关于*** RuntimeError 异常:ActionView::Helpers::ControllerHelper#response 委托给 controller.response,但控制器为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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