RunTimeError: ActionController::RackDelegation in rspec 2.10.1 for rails 3.1.4 application controller

只谈情不闲聊 提交于 2019-11-30 09:24:32

I came across this errror and realized I was triggering a redirect on the controller by calling a helper method I wanted to test, but I hadn't actually instantiated a test request yet. Calling get :index before calling the expectation got rid of the error.

it "redirects if some condition" do
  subject.send(:helper_method)
  get :action # <= Need this before setting expectation below
  response.should redirect_to("/somewhere")
end

If you want to check action mechanics, you should use should_receive before a send call like this

it "should redirect to signin_path" do
  controller.should_receive(:redirect_to).with(signin_path)
  controller.send(:require_signin) 
end

Might not be entirely useful, but I came here after getting the same error. I started with a passing test suite, made some changes, and then started getting errors like:

RuntimeError:
    ActionController::RackDelegation#status= delegated to @_response.status=, but @_response is nil:
    ...many lines...

After taking a closer look at the error, I noticed that it said somewhere:

@flashes={:alert=>"You have to confirm your account before continuing."}

I had just added the :confirmable option in Devise, and realized that all users that I created that I was trying to sign in as were unconfirmed, and as such could not successfully log in. I needed to add confirmed_at Time.now to my factory/fixture creation for users. In your example though, it seems like you are trying to test when not logged in, so I'm not sure this is necessarily applicable.

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