changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/spec/rails/matchers/render_spec.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1require File.dirname(__FILE__) + '/../../spec_helper'
2
3['isolation','integration'].each do |mode|
4 describe "response.should render_template (in #{mode} mode)",
5 :type => :controller do
6 controller_name :render_spec
7 if mode == 'integration'
8 integrate_views
9 end
10
11 it "should match a simple path" do
12 post 'some_action'
13 response.should render_template('some_action')
14 end
15
16 it "should match a less simple path" do
17 post 'some_action'
18 response.should render_template('render_spec/some_action')
19 end
20
21 it "should match a less simple path to another controller" do
22 post 'action_which_renders_template_from_other_controller'
23 response.should render_template('controller_spec/action_with_template')
24 end
25
26 it "should match a symbol" do
27 post 'some_action'
28 response.should render_template(:some_action)
29 end
30
31 it "should match an rjs template" do
32 xhr :post, 'some_action'
33 if Rails::VERSION::STRING < "2.0.0"
34 response.should render_template('render_spec/some_action.rjs')
35 else
36 response.should render_template('render_spec/some_action')
37 end
38 end
39
40 it "should match a partial template (simple path)" do
41 get 'action_with_partial'
42 response.should render_template("_a_partial")
43 end
44
45 it "should match a partial template (complex path)" do
46 get 'action_with_partial'
47 response.should render_template("render_spec/_a_partial")
48 end
49
50 it "should fail when the wrong template is rendered" do
51 post 'some_action'
52 lambda do
53 response.should render_template('non_existent_template')
54 end.should fail_with("expected \"non_existent_template\", got \"render_spec/some_action\"")
55 end
56
57 it "should fail without full path when template is associated with a different controller" do
58 post 'action_which_renders_template_from_other_controller'
59 lambda do
60 response.should render_template('action_with_template')
61 end.should fail_with(%Q|expected "action_with_template", got "controller_spec/action_with_template"|)
62 end
63
64 it "should fail with incorrect full path when template is associated with a different controller" do
65 post 'action_which_renders_template_from_other_controller'
66 lambda do
67 response.should render_template('render_spec/action_with_template')
68 end.should fail_with(%Q|expected "render_spec/action_with_template", got "controller_spec/action_with_template"|)
69 end
70
71 it "should fail on the wrong extension (given rhtml)" do
72 get 'some_action'
73 lambda {
74 response.should render_template('render_spec/some_action.rjs')
75 }.should fail_with("expected \"render_spec/some_action.rjs\", got \"render_spec/some_action\"")
76 end
77
78 it "should fail when TEXT is rendered" do
79 post 'text_action'
80 lambda do
81 response.should render_template('some_action')
82 end.should fail_with("expected \"some_action\", got nil")
83 end
84 end
85
86 describe "response.should_not render_template (in #{mode} mode)",
87 :type => :controller do
88 controller_name :render_spec
89 if mode == 'integration'
90 integrate_views
91 end
92
93 it "should pass when the action renders nothing" do
94 post 'action_that_renders_nothing'
95 response.should_not render_template('action_that_renders_nothing')
96 end
97
98 it "should pass when the action renders nothing (symbol)" do
99 post 'action_that_renders_nothing'
100 response.should_not render_template(:action_that_renders_nothing)
101 end
102
103 it "should pass when the action does not render the template" do
104 post 'some_action'
105 response.should_not render_template('some_other_template')
106 end
107
108 it "should pass when the action does not render the template (symbol)" do
109 post 'some_action'
110 response.should_not render_template(:some_other_template)
111 end
112
113 it "should pass when the action does not render the template (named with controller)" do
114 post 'some_action'
115 response.should_not render_template('render_spec/some_other_template')
116 end
117
118 it "should pass when the action renders the template with a different controller" do
119 post 'action_which_renders_template_from_other_controller'
120 response.should_not render_template('action_with_template')
121 end
122
123 it "should pass when the action renders the template (named with controller) with a different controller" do
124 post 'action_which_renders_template_from_other_controller'
125 response.should_not render_template('render_spec/action_with_template')
126 end
127
128 it "should pass when TEXT is rendered" do
129 post 'text_action'
130 response.should_not render_template('some_action')
131 end
132
133 it "should fail when the action renders the template" do
134 post 'some_action'
135 lambda do
136 response.should_not render_template('some_action')
137 end.should fail_with("expected not to render \"some_action\", but did")
138 end
139
140 it "should fail when the action renders the template (symbol)" do
141 post 'some_action'
142 lambda do
143 response.should_not render_template(:some_action)
144 end.should fail_with("expected not to render \"some_action\", but did")
145 end
146
147 it "should fail when the action renders the template (named with controller)" do
148 post 'some_action'
149 lambda do
150 response.should_not render_template('render_spec/some_action')
151 end.should fail_with("expected not to render \"render_spec/some_action\", but did")
152 end
153
154 it "should fail when the action renders the partial" do
155 post 'action_with_partial'
156 lambda do
157 response.should_not render_template('_a_partial')
158 end.should fail_with("expected not to render \"_a_partial\", but did")
159 end
160
161 it "should fail when the action renders the partial (named with controller)" do
162 post 'action_with_partial'
163 lambda do
164 response.should_not render_template('render_spec/_a_partial')
165 end.should fail_with("expected not to render \"render_spec/_a_partial\", but did")
166 end
167
168 end
169end