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
Change should_assign_to and should_not_assign_to to allow multiple names 
(#22)
showaltb (author)
Thu Jul 31 08:26:27 -0700 2008
commit  cefcfe1205f3636615e0562bba0ff60d3bf02922
tree    3ad87dc0f2392f87c23b39ce2f0b2af8d93fa1a8
parent  0de2794be2820ea22824aa6a6c3e4a940ab8f693
...
336
337
338
339
 
 
340
341
342
343
344
345
346
 
 
 
 
 
 
347
348
349
350
 
 
351
352
353
354
355
356
357
 
 
 
 
 
 
358
359
360
...
336
337
338
 
339
340
341
342
343
 
 
 
 
344
345
346
347
348
349
350
351
352
 
353
354
355
356
357
 
 
 
 
358
359
360
361
362
363
364
365
366
0
@@ -336,25 +336,31 @@ module ThoughtBot # :nodoc:
0
           should_set_the_flash_to nil
0
         end
0
         
0
- # Macro that creates a test asserting that the controller assigned to @name
0
+ # Macro that creates a test asserting that the controller assigned to
0
+ # each of the named instance variable(s).
0
         #
0
         # Example:
0
         #
0
- # should_assign_to :user
0
- def should_assign_to(name)
0
- should "assign @#{name}" do
0
- assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
0
+ # should_assign_to :user, :posts
0
+ def should_assign_to(*names)
0
+ names.each do |name|
0
+ should "assign @#{name}" do
0
+ assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
0
+ end
0
           end
0
         end
0
 
0
- # Macro that creates a test asserting that the controller did not assign to @name
0
+ # Macro that creates a test asserting that the controller did not assign to
0
+ # any of the named instance variable(s).
0
         #
0
         # Example:
0
         #
0
- # should_not_assign_to :user
0
- def should_not_assign_to(name)
0
- should "not assign to @#{name}" do
0
- assert !assigns(name.to_sym), "@#{name} was visible"
0
+ # should_not_assign_to :user, :posts
0
+ def should_not_assign_to(*names)
0
+ names.each do |name|
0
+ should "not assign to @#{name}" do
0
+ assert !assigns(name.to_sym), "@#{name} was visible"
0
+ end
0
           end
0
         end
0
 
...
39
40
41
 
 
 
 
 
 
 
 
 
42
 
43
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -39,5 +39,15 @@ class PostsControllerTest < Test::Unit::TestCase
0
       resource.create.params = { :title => "first post", :body => 'blah blah blah'}
0
       resource.update.params = { :title => "changed" }
0
     end
0
+
0
+ context "viewing posts for a user" do
0
+ setup do
0
+ get :index, :user_id => users(:first)
0
+ end
0
+ should_respond_with :success
0
+ should_assign_to :user, :posts
0
+ should_not_assign_to :foo, :bar
0
+ end
0
   end
0
+
0
 end

Comments

    No one has commented yet.