In our rails 3.1.4 app, rspec
is used to test the public method require_signin
in application controller. Here is the method require_signin:
def require_signin
if !signed_in?
flash.now.alert = "Log in first!"
redirect_to signin_path
end
end
Here is the rspec
code:
it "should invoke require_signin for those without login" do
controller.send(:require_signin)
controller {should redirect_to signin_path}
end
The above rspec
generates gigantic multi pages error starting like the below:
RuntimeError:←[0m
←[31mActionController::RackDelegation#status= delegated to @_response.status=, but @_response is nil: #<ApplicationController:0x3
a67f10 @_routes=nil, @_action_has_layout=true, @_view_context_class=nil, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_reques
t=#<ActionController::TestRequest:0x3a68720 @env={"rack.version"=>[1, 1], "rack.input"=>#<StringIO:0x34fad60>, ........
What could be wrong with the rspec
code? Thanks so much.
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:
After taking a closer look at the error, I noticed that it said somewhere:
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 addconfirmed_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.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.If you want to check action mechanics, you should use
should_receive
before asend
call like this