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

**URL:** <https://www.ruby-forum.com/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/195913>\
**Category:** Rails\
**Created:** [October 2, 2010, 8:59pm UTC](https://www.ruby-forum.com/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/195913 "2010-10-02T20:59:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@ntk](https://www.ruby-forum.com/u/ntk)\
**Post date:** [October 2, 2010, 8:59pm UTC](https://www.ruby-forum.com/t/lacking-some-enlightenment-on-why-rspec-says-i-have-a-200-response-when-i-do-not/195913/1 "2010-10-02T20:59:33Z")

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