public
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
rspec-rails / spec / rails / matchers / render_template_spec.rb
100644 177 lines (147 sloc) 6.488 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
require File.dirname(__FILE__) + '/../../spec_helper'
 
['isolation','integration'].each do |mode|
  describe "response.should render_template (in #{mode} mode)",
    :type => :controller do
    controller_name :render_spec
    if mode == 'integration'
      integrate_views
    end
 
    it "should match a simple path" do
      post 'some_action'
      response.should render_template('some_action')
    end
 
    it "should match a less simple path" do
      post 'some_action'
      response.should render_template('render_spec/some_action')
    end
  
    it "should match a less simple path to another controller" do
      post 'action_which_renders_template_from_other_controller'
      response.should render_template('controller_spec/action_with_template')
    end
  
    it "should match a symbol" do
      post 'some_action'
      response.should render_template(:some_action)
    end
  
    it "should match an rjs template" do
      xhr :post, 'some_action'
      if Rails::VERSION::STRING < "2.0.0"
        response.should render_template('render_spec/some_action.rjs')
      else
        response.should render_template('render_spec/some_action')
      end
    end
  
    it "should match a partial template (simple path)" do
      get 'action_with_partial'
      response.should render_template("_a_partial")
    end
  
    it "should match a partial template (complex path)" do
      get 'action_with_partial'
      response.should render_template("render_spec/_a_partial")
    end
  
    it "should fail when the wrong template is rendered" do
      post 'some_action'
      lambda do
        response.should render_template('non_existent_template')
      end.should fail_with(/expected \"non_existent_template\", got \"render_spec\/some_action(.rhtml)?\"/)
    end
  
    it "should fail without full path when template is associated with a different controller" do
      post 'action_which_renders_template_from_other_controller'
      lambda do
        response.should render_template('action_with_template')
      end.should fail_with(/expected \"action_with_template\", got \"controller_spec\/action_with_template(.rhtml)?\"/)
    end
  
    it "should fail with incorrect full path when template is associated with a different controller" do
      post 'action_which_renders_template_from_other_controller'
      lambda do
        response.should render_template('render_spec/action_with_template')
      end.should fail_with(/expected \"render_spec\/action_with_template\", got \"controller_spec\/action_with_template(\.rhtml)?\"/)
    end
  
    it "should fail on the wrong extension (given rhtml)" do
      get 'some_action'
      lambda {
        response.should render_template('render_spec/some_action.rjs')
      }.should fail_with(/expected \"render_spec\/some_action\.rjs\", got \"render_spec\/some_action(\.rhtml)?\"/)
    end
  
    it "should fail when TEXT is rendered" do
      post 'text_action'
      lambda do
        response.should render_template('some_action')
      end.should fail_with(/expected \"some_action\", got (nil|\"\")/)
    end
  
    describe "with an alternate layout" do
      it "should say it rendered the action's template" do
        get 'action_with_alternate_layout'
        response.should render_template('action_with_alternate_layout')
      end
    end
  end
  
  describe "response.should_not render_template (in #{mode} mode)",
    :type => :controller do
    controller_name :render_spec
    if mode == 'integration'
      integrate_views
    end
    
    it "should pass when the action renders nothing" do
      post 'action_that_renders_nothing'
      response.should_not render_template('action_that_renders_nothing')
    end
    
    it "should pass when the action renders nothing (symbol)" do
      post 'action_that_renders_nothing'
      response.should_not render_template(:action_that_renders_nothing)
    end
    
    it "should pass when the action does not render the template" do
      post 'some_action'
      response.should_not render_template('some_other_template')
    end
    
    it "should pass when the action does not render the template (symbol)" do
      post 'some_action'
      response.should_not render_template(:some_other_template)
    end
    
    it "should pass when the action does not render the template (named with controller)" do
      post 'some_action'
      response.should_not render_template('render_spec/some_other_template')
    end
    
    it "should pass when the action renders the template with a different controller" do
      post 'action_which_renders_template_from_other_controller'
      response.should_not render_template('action_with_template')
    end
    
    it "should pass when the action renders the template (named with controller) with a different controller" do
      post 'action_which_renders_template_from_other_controller'
      response.should_not render_template('render_spec/action_with_template')
    end
    
    it "should pass when TEXT is rendered" do
      post 'text_action'
      response.should_not render_template('some_action')
    end
    
    it "should fail when the action renders the template" do
      post 'some_action'
      lambda do
        response.should_not render_template('some_action')
      end.should fail_with("expected not to render \"some_action\", but did")
    end
    
    it "should fail when the action renders the template (symbol)" do
      post 'some_action'
      lambda do
        response.should_not render_template(:some_action)
      end.should fail_with("expected not to render \"some_action\", but did")
    end
    
    it "should fail when the action renders the template (named with controller)" do
      post 'some_action'
      lambda do
        response.should_not render_template('render_spec/some_action')
      end.should fail_with("expected not to render \"render_spec/some_action\", but did")
    end
    
    it "should fail when the action renders the partial" do
      post 'action_with_partial'
      lambda do
        response.should_not render_template('_a_partial')
      end.should fail_with("expected not to render \"_a_partial\", but did")
    end
    
    it "should fail when the action renders the partial (named with controller)" do
      post 'action_with_partial'
      lambda do
        response.should_not render_template('render_spec/_a_partial')
      end.should fail_with("expected not to render \"render_spec/_a_partial\", but did")
    end
        
  end
end