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
add a :class option to should_assign_to which checks that the instance 
vars are of the correct class
mjankowski (author)
Sat Sep 20 12:11:57 -0700 2008
tsaleh (committer)
Sat Sep 20 12:35:38 -0700 2008
commit  a62c376628d01773899305b05e9be03f28d79e9f
tree    13ac21b0df98e7737614a368ecdcfbbbe94c25b8
parent  2c41a563f9e4804e40a3995cfcf4d9e01a7d9ca9
...
99
100
101
 
 
 
102
103
104
 
105
 
106
107
108
 
 
 
109
110
111
...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -99,13 +99,21 @@ module ThoughtBot # :nodoc:
0
         # Macro that creates a test asserting that the controller assigned to
0
         # each of the named instance variable(s).
0
         #
0
+ # Options:
0
+ # * <tt>:class</tt> - The expected class of the instance variable being checked.
0
+ #
0
         # Example:
0
         #
0
         # should_assign_to :user, :posts
0
+ # should_assign_to :user, :class => User
0
         def should_assign_to(*names)
0
+ opts = names.extract_options!
0
           names.each do |name|
0
             should "assign @#{name}" do
0
               assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
0
+ unless opts[:class].nil?
0
+ assert_kind_of opts[:class], assigns(name.to_sym)
0
+ end
0
             end
0
           end
0
         end
...
64
65
66
67
 
 
 
 
 
68
69
70
...
64
65
66
 
67
68
69
70
71
72
73
74
0
@@ -64,7 +64,11 @@ class PostsControllerTest < Test::Unit::TestCase
0
         get :index, :user_id => users(:first)
0
       end
0
       should_respond_with :success
0
- should_assign_to :user, :posts
0
+ should_assign_to :user, :class => User
0
+ should_fail do
0
+ should_assign_to :user, :class => Post
0
+ end
0
+ should_assign_to :posts
0
       should_not_assign_to :foo, :bar
0
     end
0
 

Comments

    No one has commented yet.