Michael MacDonald

Testing flash.now with RSpec

In Rails, Testing on July 12, 2009 at 9:56 pm

A recent Rails upgrade created some failing specs. One spec in particular caused me some frustration. It was a simple controller spec that was verifying the message of a flash.now warning. It worked find in Rails 2.1.0 but was failing in Rails 2.3.2. The solution was to simply inspect the response object!

Instead of:

flash[:warning].should eql('Are you sure you should be doing that?')

use:

response.flash[:warning].should eql('Are you sure you should be doing that?')

Thumbs up to my work colleague Abhijat for that tip!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: