v0.3 of Flash Helper Plugin
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_messageswas always returning the enclosingdiv. 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 !