# RSpec, flash messages and redirection

**URL:** <https://www.ruby-forum.com/t/rspec-flash-messages-and-redirection/177233>\
**Category:** Rails\
**Created:** [October 13, 2009, 10:20pm UTC](https://www.ruby-forum.com/t/rspec-flash-messages-and-redirection/177233 "2009-10-13T22:20:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo72](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/71c47a/32.png) [@leo72](https://www.ruby-forum.com/u/leo72)\
**Post date:** [October 13, 2009, 10:20pm UTC](https://www.ruby-forum.com/t/rspec-flash-messages-and-redirection/177233/1 "2009-10-13T22:20:57Z")

</div>

Hello everybody  
I’m having some problems with RSpec.

1. When using something like “I should see ‘some text’”  
that text is set on a flash message in the controller and displayed by  
= flash[:notice] in the layout view, so the relevant part of my view  
says, in haml:  
.notice  
= flash[:notice]  
The rspec evaluation for that says:  
response.should have\_text(“blah”)

The spec fails saying that the text “blah” cannot be found on the  
response, shows the HTML code that rspec got and, in fact, the text is  
not there.  
But, if I run the application, the text is shown, even when I run the  
application on test mode (RAILS\_ENV=test script/server)

I don’t know what can be the difference, it seems that the testing  
execution of RSpec is not the same that the application execution.

1. When using something like "response.redirected\_to.should == “/login”  
The RSpec execution is not redirected, the response object has the  
status “200 OK”, but if I run the application in that circumstances,  
it gets redirected.

It seems like I’m missing something, I’ve used this things  
successfully in the past and I don’t know what can be wrong now.  
I’m using rspec 1.2.9 and rspec-rails 1.2.9., both set up on the  
config/environments/test.rb via config.gem “rspec”, :lib =\> false,  
:version =\> “\>= 1.2.9”

If you need the code, I can “pastie” it, but I don’t know if it will  
add noise to the problem description.

Thanx a lot in advance.

–  
Leonardo M…  
There’s no place like ~
