public
Rubygem
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
'should render_template' ignores layouts [#508 state:resolved]
David Chelimsky (author)
Mon Aug 25 06:15:31 -0700 2008
commit  e11c5b58f1a85dbd260bca96410740c12fda21f4
tree    9189740b6bfecf2401d8697a71b937e02a4d18f0
parent  68226c616856554fd1d68af959fbdb94b0e46b78
...
183
184
185
186
187
188
 
189
190
191
192
193
194
 
195
196
197
198
199
 
200
201
202
203
204
205
206
207
208
209
 
 
210
211
212
...
278
279
280
 
 
 
 
 
281
282
283
...
183
184
185
 
 
 
186
187
188
189
 
 
 
190
191
192
193
194
 
195
196
197
198
 
 
 
 
 
 
 
199
200
201
202
203
...
269
270
271
272
273
274
275
276
277
278
279
0
@@ -183,30 +183,21 @@ module Spec
0
               unless integrate_views?
0
                 if @template.respond_to?(:finder)
0
                   (class << @template.finder; self; end).class_eval do
0
-                    define_method :file_exists? do
0
-                      true
0
-                    end
0
+                    define_method :file_exists? do; true; end
0
                   end
0
                 else
0
                   (class << @template; self; end).class_eval do
0
-                    define_method :file_exists? do
0
-                      true
0
-                    end
0
+                    define_method :file_exists? do; true; end
0
                   end
0
                 end
0
                 (class << @template; self; end).class_eval do
0
                   define_method :render_file do |*args|
0
-                    @first_render ||= args[0] 
0
+                    @first_render ||= args[0] unless args[0] =~ /^layouts/
0
                   end
0
                   
0
                   define_method :pick_template do |*args|
0
-                    @_first_render = args[0]
0
-                    Class.new do
0
-                      def render_template(*ignore_args)
0
-                      end
0
-                      def render_partial(*ignore_args)
0
-                      end
0
-                    end.new
0
+                    @_first_render ||= args[0] unless args[0] =~ /^layouts/
0
+                    PickedTemplate.new
0
                   end
0
                 end
0
               end
0
@@ -278,6 +269,11 @@ module Spec
0
 
0
         Spec::Example::ExampleGroupFactory.register(:controller, self)
0
       end
0
+      
0
+      class PickedTemplate
0
+        def render_template(*ignore_args); end
0
+        def render_partial(*ignore_args);  end
0
+      end
0
     end
0
   end
0
 end
...
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
 
 
 
 
26
27
28
...
41
42
43
44
 
 
45
46
47
...
50
51
52
53
54
55
56
57
58
59
60
...
10
11
12
13
14
15
 
16
17
 
 
 
 
 
 
 
18
19
20
21
22
23
24
25
...
38
39
40
 
41
42
43
44
45
...
48
49
50
 
 
 
 
 
51
52
53
0
@@ -10,19 +10,16 @@ module Spec
0
         end
0
       
0
         def matches?(response)
0
+          
0
           if response.respond_to?(:rendered_file)
0
             @actual = response.rendered_file
0
-            full_path(@actual) == full_path(@expected)
0
           else
0
             @actual = response.rendered_template.to_s
0
-            if @expected =~ /\//
0
-              given_controller_path, given_file = path_and_file(@actual)
0
-              expected_controller_path, expected_file = path_and_file(@expected)
0
-              given_controller_path == expected_controller_path && given_file.match(expected_file)
0
-            else
0
-              current_controller_path == controller_path_from(@actual) && @actual.match(@expected)
0
-            end
0
           end
0
+          return false if @actual.blank?
0
+          given_controller_path, given_file = path_and_file(@actual)
0
+          expected_controller_path, expected_file = path_and_file(@expected)
0
+          given_controller_path == expected_controller_path && given_file.match(expected_file)
0
         end
0
         
0
         def failure_message
0
@@ -41,7 +38,8 @@ module Spec
0
           def path_and_file(path)
0
             parts = path.split('/')
0
             file = parts.pop
0
-            return parts.join('/'), file
0
+            controller = parts.empty? ? current_controller_path : parts.join('/')
0
+            return controller, file
0
           end
0
         
0
           def controller_path_from(path)
0
@@ -50,11 +48,6 @@ module Spec
0
             parts.join('/')
0
           end
0
 
0
-          def full_path(path)
0
-            return nil if path.nil?
0
-            path.include?('/') ? path : "#{current_controller_path}/#{path}"
0
-          end
0
-        
0
           def current_controller_path
0
             @controller.class.to_s.underscore.gsub(/_controller$/,'')
0
           end
...
23
24
25
 
 
 
 
26
...
23
24
25
26
27
28
29
30
0
@@ -23,4 +23,8 @@ class RenderSpecController < ApplicationController
0
   def action_that_renders_nothing
0
     render :nothing => true
0
   end
0
+  
0
+  def action_with_alternate_layout
0
+    render :layout => 'simple'
0
+  end
0
 end

Comments