*** RuntimeError Exception: ActionView::Helpers::ControllerHelper#response delegated to controller.response, but controller is nil

岁酱吖の 提交于 2019-12-24 12:25:28

问题


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

I have a controller under controllers/api/v1/catalog_controller.rb

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

The matching spec for it is under 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

Any idea what I could be doing wrong?


回答1:


I've resolved the issue by removing the line

 config.include ActionView::Helpers

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.



来源:https://stackoverflow.com/questions/22875355/runtimeerror-exception-actionviewhelperscontrollerhelperresponse-deleg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!