public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
refactored flash tests

git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@203 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Fri Aug 31 07:46:05 -0700 2007
commit  e8c72447d3fd1420c148bf589db2a4bfe5faa5e8
tree    655dccbba4b9d10e1e37c9da381901d3df2811d9
parent  725e7f61b11b451dc61e495c4d12934b93be0fe0
...
211
212
213
 
 
 
 
 
 
 
 
 
214
215
216
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
306
307
308
309
 
310
311
312
 
313
 
314
315
316
 
 
 
 
 
 
 
 
317
318
319
320
 
 
321
322
323
324
 
325
326
327
...
367
368
369
 
 
370
371
372
 
 
373
374
375
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
251
252
253
 
 
 
 
 
 
 
 
254
255
256
...
307
308
309
 
310
311
312
313
314
315
316
317
 
 
318
319
320
321
322
323
324
325
326
327
328
 
329
330
331
 
 
 
332
333
334
335
...
375
376
377
378
379
380
381
 
382
383
384
385
386
0
@@ -211,6 +211,15 @@ module ThoughtBot # :nodoc:
0
             @update = ActionOptions.new
0
             @destroy = ActionOptions.new
0
             @denied = DeniedOptions.new
0
+
0
+ @create.flash ||= /created/i
0
+ @update.flash ||= /updated/i
0
+ @destroy.flash ||= /removed/i
0
+ @denied.flash ||= /denied/i
0
+
0
+ @create.params ||= {}
0
+ @update.params ||= {}
0
+
0
             @actions = VALID_ACTIONS
0
             @formats = VALID_FORMATS
0
             @denied.actions = []
0
@@ -242,14 +251,6 @@ module ThoughtBot # :nodoc:
0
             @create.redirect ||= "#{@object}_url(#{singular_args.join(', ')})"
0
             @update.redirect ||= "#{@object}_url(#{singular_args.join(', ')})"
0
             @denied.redirect ||= "new_session_url"
0
-
0
- @create.flash ||= /created/i
0
- @update.flash ||= /updated/i
0
- @destroy.flash ||= /removed/i
0
- @denied.flash ||= /denied/i
0
-
0
- @create.params ||= {}
0
- @update.params ||= {}
0
           end
0
           
0
           private
0
@@ -306,22 +307,29 @@ module ThoughtBot # :nodoc:
0
         # :section: Test macros
0
         
0
         # Macro that creates a test asserting that the flash contains the given value.
0
- # val can be a String or a Regex
0
+ # val can be a String, a Regex, or nil (indicating that the flash should not be set)
0
         #
0
         # Example:
0
         #
0
+ # should_set_the_flash_to "Thank you for placing this order."
0
         # should_set_the_flash_to /created/i
0
+ # should_set_the_flash_to nil
0
         def should_set_the_flash_to(val)
0
- should "have #{val.inspect} in the flash" do
0
- assert_contains flash.values, val, ", Flash: #{flash.inspect}"
0
+ if val
0
+ should "have #{val.inspect} in the flash" do
0
+ assert_contains flash.values, val, ", Flash: #{flash.inspect}"
0
+ end
0
+ else
0
+ should "not set the flash" do
0
+ assert_equal({}, flash, "Flash was set to:\n#{flash.inspect}")
0
+ end
0
           end
0
         end
0
     
0
- # Macro that creates a test asserting that the flash is empty
0
+ # Macro that creates a test asserting that the flash is empty. Same as
0
+ # @should_set_the_flash_to nil@
0
         def should_not_set_the_flash
0
- should "not set the flash" do
0
- assert_equal({}, flash, "Flash was set to:\n#{flash.inspect}")
0
- end
0
+ should_set_the_flash_to nil
0
         end
0
         
0
         # Macro that creates a test asserting that the controller assigned to @name
0
@@ -367,9 +375,12 @@ module ThoughtBot # :nodoc:
0
         end
0
 
0
         # Macro that creates a test asserting that the controller returned a redirect to the given path.
0
+ # The given string is evaled to produce the resulting redirect path. All of the instance variables
0
+ # set by the controller are available to the evaled string.
0
         # Example:
0
         #
0
- # should_redirect_to "/"
0
+ # should_redirect_to '"/"'
0
+ # should_redirect_to "users_url(@user)"
0
         def should_redirect_to(url)
0
           should "redirect to \"#{url}\"" do
0
             instantiate_variables_from_assigns do

Comments

    No one has commented yet.