*** RuntimeError异常:ActionView :: Helpers :: ControllerHelper#response委托给controller.response,但是控制器是nil

时间:2014-04-05 01:01:25

标签: ruby-on-rails ruby rspec

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

*** 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

知道我可能做错了吗?

1 个答案:

答案 0 :(得分:1)

我已通过删除

行解决了这个问题
 config.include ActionView::Helpers

来自我的spec_helper.rb配置块。我想这是相互矛盾的。我并不十分清楚为什么这么进一步的见解会很棒。