This article and the plugin it describes are obsolete. There are replacements for neighter. The code is still available if you want to play around with it.

A new day, a new release !

What’s changed ?

  • A heinous bug was corrected that prevented flash.now from being correctly appended to.
  • #show_flash_messages was always returning the enclosing div. Now, it will only return something if the keys contain something.
  • Assertions for your unit tests. See below for details.
  • Renamed middle package from flash_plugin_helper to flash_helper_plugin. This should not have any impact on your code.

The interesting feature in this version are the new assertions. For example, the following code:

1 def test_destroy
2   post :destroy, :id => contacts(:bob).id
3 
4   assert_match /bob.*destroyed successfully/i,
5                flash[:notice],
6                "User notified that Bob was deleted"
7 end

can be expressed like this instead:

1 def test_destroy
2   post :destroy, :id => contacts(:bob).id
3 
4   assert_success_flash_contains \
5       /bob.*destroyed successfully/i,
6       'User notified that Bob was deleted'
7 end

The reverse is also true:

1 def test_pre_authorization_granted
2   get :index, {}, {:user_id => accounts(:bob).id}
3 
4   assert_any_flash_does_not_contain \
5       /not authorized/i,
6       'Authorization granted'
7 end

There are eight assertion methods added to Test::Unit::TestCase:

  • #assert_any_flash_contains(string_or_regexp, msg=nil)
  • #assert_any_flash_does_not_contain(string_or_regexp, msg=nil)
  • #assert_failure_flash_contains(string_or_regexp, msg=nil)
  • #assert_failure_flash_does_not_contain(string_or_regexp, msg=nil)
  • #assert_success_flash_contains(string_or_regexp, msg=nil)
  • #assert_success_flash_does_not_contain(string_or_regexp, msg=nil)
  • #assert_message_flash_contains(string_or_regexp, msg=nil)
  • #assert_message_flash_does_not_contain(string_or_regexp, msg=nil)

The any variants of the assertions check all message keys: :notice, :message and :warning. All messages are concatenated, and the assertion is made against the resulting string.

In addition, four building block assertions are also added:

  • #assert_flash_contains(key, string_or_regexp, msg=nil)
  • #assert_flash_does_not_contain(key, string_or_regexp, msg=nil)
  • #assert_in_contents(string_or_regexp, contents, msg=nil)
  • #assert_not_in_contents(string_or_regexp, contents, msg=nil)

And last, but not least, the #flash_contents(key) method returns the flash’s contents, as a string, whether it was an Array or a String to begin with.

If anybody is using this in production, would you drop me an E-Mail ?

Enjoy !

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on