public
Rubygem
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
Update handling of rendering to accomodate changes in edge rails. [#471 
state:resolved milestone:"1.1.5"]
David Chelimsky (author)
Thu Jul 17 20:58:17 -0700 2008
commit  6499e4e0d26451c090d88c4312fa245c189979b1
tree    fd957c4852b28996be75880ec37433ae04b94412
parent  6c6e0ded3bd72244bcfdaba854ac5e2e634c8e1d
...
196
197
198
199
 
 
200
201
202
...
196
197
198
 
199
200
201
202
203
0
@@ -196,7 +196,8 @@ module Spec
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] # rails up 2.1.0
0
+                    @_first_render ||= args[0] # rails edge > 2.1.0
0
                   end
0
                 end
0
               end
...
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
 
17
18
19
...
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
 
 
 
 
 
33
34
35
...
10
11
12
 
 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
27
28
29
30
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
55
56
57
58
59
60
61
62
0
@@ -10,10 +10,21 @@ module Spec
0
         end
0
       
0
         def matches?(response)
0
-          @actual = response.rendered_file
0
-          full_path(@actual) == full_path(@expected)
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
         end
0
-
0
+        
0
         def failure_message
0
           "expected #{@expected.inspect}, got #{@actual.inspect}"
0
         end
0
@@ -27,9 +38,25 @@ module Spec
0
         end
0
       
0
         private
0
+          def path_and_file(path)
0
+            parts = path.split('/')
0
+            file = parts.pop
0
+            return parts.join('/'), file
0
+          end
0
+        
0
+          def controller_path_from(path)
0
+            parts = path.split('/')
0
+            parts.pop
0
+            parts.join('/')
0
+          end
0
+
0
           def full_path(path)
0
             return nil if path.nil?
0
-            path.include?('/') ? path : "#{@controller.class.to_s.underscore.gsub('_controller','')}/#{path}"
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
0
         
0
       end
...
7
8
9
10
 
11
12
13
...
51
52
53
54
 
55
56
57
58
59
60
61
 
62
63
64
65
66
67
68
 
69
70
71
72
73
74
75
 
76
77
78
79
80
81
82
 
83
84
85
...
7
8
9
 
10
11
12
13
...
51
52
53
 
54
55
56
57
58
59
60
 
61
62
63
64
65
66
67
 
68
69
70
71
72
73
74
 
75
76
77
78
79
80
81
 
82
83
84
85
0
@@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
0
     if mode == 'integration'
0
       integrate_views
0
     end
0
-    
0
+
0
     it "should match a simple path" do
0
       post 'some_action'
0
       response.should render_template('some_action')
0
@@ -51,35 +51,35 @@ require File.dirname(__FILE__) + '/../../spec_helper'
0
       post 'some_action'
0
       lambda do
0
         response.should render_template('non_existent_template')
0
-      end.should fail_with("expected \"non_existent_template\", got \"render_spec/some_action\"")
0
+      end.should fail_with(/expected \"non_existent_template\", got \"render_spec\/some_action(.rhtml)?\"/)
0
     end
0
 
0
     it "should fail without full path when template is associated with a different controller" do
0
       post 'action_which_renders_template_from_other_controller'
0
       lambda do
0
         response.should render_template('action_with_template')
0
-      end.should fail_with(%Q|expected "action_with_template", got "controller_spec/action_with_template"|)
0
+      end.should fail_with(/expected \"action_with_template\", got \"controller_spec\/action_with_template(.rhtml)?\"/)
0
     end
0
 
0
     it "should fail with incorrect full path when template is associated with a different controller" do
0
       post 'action_which_renders_template_from_other_controller'
0
       lambda do
0
         response.should render_template('render_spec/action_with_template')
0
-      end.should fail_with(%Q|expected "render_spec/action_with_template", got "controller_spec/action_with_template"|)
0
+      end.should fail_with(/expected \"render_spec\/action_with_template\", got \"controller_spec\/action_with_template(\.rhtml)?\"/)
0
     end
0
 
0
     it "should fail on the wrong extension (given rhtml)" do
0
       get 'some_action'
0
       lambda {
0
         response.should render_template('render_spec/some_action.rjs')
0
-      }.should fail_with("expected \"render_spec/some_action.rjs\", got \"render_spec/some_action\"")
0
+      }.should fail_with(/expected \"render_spec\/some_action\.rjs\", got \"render_spec\/some_action(\.rhtml)?\"/)
0
     end
0
 
0
     it "should fail when TEXT is rendered" do
0
       post 'text_action'
0
       lambda do
0
         response.should render_template('some_action')
0
-      end.should fail_with("expected \"some_action\", got nil")
0
+      end.should fail_with(/expected \"some_action\", got (nil|\"\")/)
0
     end
0
   end
0
   

Comments