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'
9 it "should provide controller.session as session" do
10 get 'action_with_template'
11 session.should equal(controller.session)
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)
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'
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
30 it "should allow specifying a partial with partial name only" do
31 get 'action_with_partial'
32 response.should render_template("_partial")
35 it "should allow specifying a partial with expect_render" do
36 controller.expect_render(:partial => "controller_spec/partial")
37 get 'action_with_partial'
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"
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"
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")
55 it "should provide access to flash" do
56 get 'action_with_template'
57 flash[:flash_key].should == "flash value"
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"
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"
70 it "should provide access to session" do
71 get 'action_with_template'
72 session[:session_key].should == "session value"
75 it "should support custom routes" do
76 route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
79 it "should support existing routes" do
80 route_for(:controller => "controller_spec", :action => "some_action").should == "/controller_spec/some_action"
83 it "should generate params for custom routes" do
84 params_from(:get, '/custom_route').should == {:controller => "custom_route_spec", :action => "custom_route"}
87 it "should generate params for existing routes" do
88 params_from(:get, '/controller_spec/some_action').should == {:controller => "controller_spec", :action => "some_action"}
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
96 it "should complain when calling should_receive(:render) on the controller" do
98 controller.should_receive(:render)
99 }.should raise_error(RuntimeError, /should_receive\(:render\) has been disabled/)
102 it "should complain when calling stub!(:render) on the controller" do
104 controller.stub!(:render)
105 }.should raise_error(RuntimeError, /stub!\(:render\) has been disabled/)
108 it "should NOT complain when calling should_receive with arguments other than :render" do
109 controller.should_receive(:anything_besides_render)
111 controller.rspec_verify
112 }.should raise_error(Exception, /expected :anything_besides_render/)
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")
127 it "a call to response.should redirect_to should fail if no redirect" do
128 get 'action_with_no_redirect'
130 response.redirect?.should be_true
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")
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")
146 # Spec::Expectations::ExpectationNotMetError,
147 # /You have to declare the controller name in controller specs/
154 describe ControllerSpecController, :behaviour_type => :controller do
155 it "should not require naming the controller if describe is passed a type" do