Rails flash tests deprecated?

After returning from a weekend away, updating my apps to the latest Edge Rails, and running my test suite I started spotting new deprecation warnings:

DEPRECATION WARNING: assert_flash_exists is deprecated and will be removed from Rails 2.0
DEPRECATION WARNING: assert_flash_has is deprecated and will be removed from Rails 2.0

Kevin Clark has posted on the deprecation of assert_tag in favour of assert_select, but I’ve yet to see any notes on this one. Looking in the actionpack CHANGELOG there’s no reference to the change, and there’s no documentation in the new home of those methods (actionpack/lib/actioncontroller/assertions/deprecated_assertions.rb) to suggest what we should use instead other perhaps than making use of the code used in those methods. eg:

assert_flash_has :notice
assert_flash_equals :notice, 'This is a notice'


assert @response.has_flash_object?(:notice)
assert_equal 'This is a notice', @response.flash[:notice]

Obviously testing the flash contents is not a way to test the key behaviours of an application, but I often use these tests to make sure I’ve remembered to set notices in the right places. Does anyone know why they’ve been deprecated?

Tags: , , , ,


  1. Hi there. assert_flash_equals and friends were deprecated around 0.11 if I recall. The core decided that there were too many specific assertions in Rails itself. If you still want these things feel free to pull your own versions into test/test_helper.rb

  2. Ah. I guess I must have been thrown by the newly added deprecation warnings? Thanks for clarifying.