Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec_on_rails / spec / rails / dsl / controller_spec_spec.rb
blob9d1e527e19d66f4b78ba601bf346ec6b765a956c
1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'controller_spec_controller'
4 ['integration', 'isolation'].each do |mode|
5   describe "A controller example running in #{mode} mode", :behaviour_type => :controller do
6     controller_name :controller_spec
7     integrate_views if mode == 'integration'
8   
9     it "should provide controller.session as session" do
10       get 'action_with_template'
11       session.should equal(controller.session)
12     end
13   
14     it "should provide the same session object before and after the action" do
15       session_before = session
16       get 'action_with_template'
17       session.should equal(session_before)
18     end
19   
20     it "should ensure controller.session is NOT nil before the action" do
21       controller.session.should_not be_nil
22       get 'action_with_template'
23     end
24     
25     it "should ensure controller.session is NOT nil after the action" do
26       get 'action_with_template'
27       controller.session.should_not be_nil
28     end
29     
30     it "should allow specifying a partial with partial name only" do
31       get 'action_with_partial'
32       response.should render_template("_partial")
33     end
34     
35     it "should allow specifying a partial with expect_render" do
36       controller.expect_render(:partial => "controller_spec/partial")
37       get 'action_with_partial'
38     end
39     
40     it "should allow specifying a partial with expect_render with object" do
41       controller.expect_render(:partial => "controller_spec/partial", :object => "something")
42       get 'action_with_partial_with_object', :thing => "something"
43     end
44     
45     it "should allow specifying a partial with expect_render with locals" do
46       controller.expect_render(:partial => "controller_spec/partial", :locals => {:thing => "something"})
47       get 'action_with_partial_with_locals', :thing => "something"
48     end
49     
50     it "should allow a path relative to RAILS_ROOT/app/views/ when specifying a partial" do
51       get 'action_with_partial'
52       response.should render_template("controller_spec/_partial")
53     end
54     
55     it "should provide access to flash" do
56       get 'action_with_template'
57       flash[:flash_key].should == "flash value"
58     end
59     
60     it "should provide access to flash values set after a session reset" do
61       get 'action_setting_flash_after_session_reset'
62       flash[:after_reset].should == "available"
63     end
64     
65     it "should not provide access to flash values set before a session reset" do
66       get 'action_setting_flash_before_session_reset'
67       flash[:before_reset].should_not == "available"
68     end
70     it "should provide access to session" do
71       get 'action_with_template'
72       session[:session_key].should == "session value"
73     end
75     it "should support custom routes" do
76       route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
77     end
79     it "should support existing routes" do
80       route_for(:controller => "controller_spec", :action => "some_action").should == "/controller_spec/some_action"
81     end
83     it "should generate params for custom routes" do
84       params_from(:get, '/custom_route').should == {:controller => "custom_route_spec", :action => "custom_route"}
85     end
86     
87     it "should generate params for existing routes" do
88       params_from(:get, '/controller_spec/some_action').should == {:controller => "controller_spec", :action => "some_action"}
89     end
90     
91     it "should expose the assigns hash directly" do
92       get 'action_setting_the_assigns_hash'
93       assigns[:direct_assigns_key].should == :direct_assigns_key_value
94     end
95     
96     it "should complain when calling should_receive(:render) on the controller" do
97       lambda {
98         controller.should_receive(:render)
99       }.should raise_error(RuntimeError, /should_receive\(:render\) has been disabled/)
100     end
102     it "should complain when calling stub!(:render) on the controller" do
103       lambda {
104         controller.stub!(:render)
105       }.should raise_error(RuntimeError, /stub!\(:render\) has been disabled/)
106     end
107     
108     it "should NOT complain when calling should_receive with arguments other than :render" do
109       controller.should_receive(:anything_besides_render)
110       lambda {
111         controller.rspec_verify
112       }.should raise_error(Exception, /expected :anything_besides_render/)
113     end
114   end
116   describe "Given a controller spec for RedirectSpecController running in #{mode} mode", :behaviour_type => :controller do
117     controller_name :redirect_spec
118     integrate_views if mode == 'integration'
120     it "a redirect should ignore the absence of a template" do
121       get 'action_with_redirect_to_somewhere'
122       response.should be_redirect
123       response.redirect_url.should == "http://test.host/redirect_spec/somewhere"
124       response.should redirect_to("http://test.host/redirect_spec/somewhere")
125     end
126     
127     it "a call to response.should redirect_to should fail if no redirect" do
128       get 'action_with_no_redirect'
129       lambda {
130         response.redirect?.should be_true
131       }.should fail
132       lambda {
133         response.should redirect_to("http://test.host/redirect_spec/somewhere")
134       }.should fail_with("expected redirect to \"http://test.host/redirect_spec/somewhere\", got no redirect")
135     end
136   end
137   
138   describe "Given a controller spec running in #{mode} mode" do
139     example_group = describe "A controller spec"
140     # , :behaviour_type => :controller do
141     # integrate_views if mode == 'integration'
142     it "a spec in a context without controller_name set should fail with a useful warning" do
143       pending("need a new way to deal with examples that should_raise")
144     # ,
145     #   :should_raise => [
146     #     Spec::Expectations::ExpectationNotMetError,
147     #     /You have to declare the controller name in controller specs/
148     #   ] do
149     end
150   end
151   
154 describe ControllerSpecController, :behaviour_type => :controller do
155   it "should not require naming the controller if describe is passed a type" do
156   end