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 should_render_with_layout and should_render_without_layout
mjankowski (author)
Sun Sep 14 17:26:17 -0700 2008
tsaleh (committer)
Mon Sep 15 11:15:13 -0700 2008
commit  2d858c0b08ca5e93e389730bfc591c3cce39b9f9
tree    f71223bfce5730d3bb3b7eaa76092fd46bcdae06
parent  99b1189c3cf27928d27638e5ec518fe5dc7ff865
...
148
149
150
151
 
152
153
154
...
175
176
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
179
180
...
148
149
150
 
151
152
153
154
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
0
@@ -148,7 +148,7 @@ module ThoughtBot # :nodoc:
0
             end
0
           end
0
         end
0
-
0
+
0
         # Macro that creates a test asserting that a value returned from the session is correct.
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
@@ -175,6 +175,24 @@ module ThoughtBot # :nodoc:
0
           end
0
         end
0
 
0
+ # Macro that creates a test asserting that the controller rendered with the given layout.
0
+ # Example:
0
+ #
0
+ # should_render_with_layout 'special'
0
+ def should_render_with_layout(expected_layout = 'application')
0
+ expected_layout ||= false
0
+ should "render with #{expected_layout} layout" do
0
+ response_layout = @response.layout.blank? ? false : @response.layout.split('/').last
0
+ assert_equal expected_layout, response_layout, "Expected #{expected_layout} but was #{response_layout}"
0
+ end
0
+ end
0
+
0
+ # Macro that creates a test asserting that the controller rendered without a layout.
0
+ # Same as @should_render_with_layout false@
0
+ def should_render_without_layout
0
+ should_render_with_layout nil
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.
...
82
83
84
 
 
 
 
 
 
 
 
 
 
85
86
87
...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -82,6 +82,16 @@ class PostsControllerTest < Test::Unit::TestCase
0
       should_assign_to :user, :posts
0
       should_not_assign_to :foo, :bar
0
     end
0
+
0
+ context "viewing a post on GET to #show" do
0
+ setup { get :show, :user_id => users(:first), :id => posts(:first) }
0
+ should_render_with_layout 'wide'
0
+ end
0
+
0
+ context "on GET to #new" do
0
+ setup { get :new, :user_id => users(:first) }
0
+ should_render_without_layout
0
+ end
0
   end
0
 
0
 end
...
21
22
23
24
 
25
26
27
28
29
30
 
31
32
33
...
21
22
23
 
24
25
26
27
28
29
30
31
32
33
34
0
@@ -21,13 +21,14 @@ class PostsController < ApplicationController
0
     @post = @user.posts.find(params[:id])
0
 
0
     respond_to do |format|
0
- format.html # show.rhtml
0
+ format.html { render :layout => 'wide' }
0
       format.xml { render :xml => @post.to_xml }
0
     end
0
   end
0
 
0
   def new
0
     @post = @user.posts.build
0
+ render :layout => false
0
   end
0
 
0
   def edit

Comments

    No one has commented yet.