# Lacking some enlightenment on why rspec says I have a 200 response when I do not

**URL:** <https://discuss.rubyonrails.org/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/54793>\
**Category:** rubyonrails-talk\
**Created:** [October 2, 2010, 6:58pm UTC](https://discuss.rubyonrails.org/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/54793 "2010-10-02T18:58:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DK11](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@DK11](https://discuss.rubyonrails.org/u/DK11)\
**Post date:** [October 2, 2010, 6:58pm UTC](https://discuss.rubyonrails.org/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/54793/1 "2010-10-02T18:58:30Z")

</div>

I am writing a few low level tests for my controllers to verify security. New to rspec and am seeing some unexpected activity: If I run this spec: describe “GET index” do it “does not load for guest role” do get :new flash[:notice].should match RESTRICTED\_PAGE\_NOTICE response.should redirect\_to(login\_path) end Which hits class PracticesController \< ApplicationController def index @practices = Practice.all respond\_to do |format| format.html # index.html.erb end end end But the controller also inherits from the application controller which: class ApplicationController … when ‘practices’ flash[:notice] = RESTRICTED\_PAGE\_NOTICE redirect\_to login\_path if action\_name != ‘new’ && action\_name != ‘create’ end I have verified the redirect and message in a browser, so this code is executing as expected in ‘reality’. Then why do I get this error:

1. PracticesController GET index does not load for guest role Failure/Error: response.should redirect\_to(login\_path) **Expected response to be a \<:redirect\>, but was \<200\>.** Expected block to return true value.

It is true, if the controller is isolated and not inheriting from the app controller, it would be a 200. But with the app controller it should redirect before it ever hits the method.

The line in the app controller “flash[:notice] = RESTRICTED\_PAGE\_NOTICE” clearly gets evaluated as the line in the spec “flash[:notice].should match RESTRICTED\_PAGE\_NOTICE” passes, _BUT_ this line in the app controller “redirect\_to login\_path if action\_name != ‘new’ && action\_name != ‘create’” does not get evaluated as rspec says I have a 200 response? I am really confused and don’t like what feels to be a weird paradox…

Can anyone enlighten me?

Thanks,

David
