1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'controller_spec_controller'
4 ['integration', 'isolation'].each do |mode|
5 describe "Given a controller spec for ControllerSpecController running in #{mode} mode", :behaviour_type => :controller do
6 controller_name :controller_spec
7 integrate_views if mode == 'integration'
9 it "session should be the same object as controller session" do
10 get 'action_with_template'
11 session.should equal(controller.session)
14 it "session should be the same object before and after the action" do
15 session_before = session
16 get 'action_with_template'
17 session.should equal(session_before)
20 it "controller.session should NOT be nil before the action" do
21 controller.session.should_not be_nil
22 get 'action_with_template'
25 it "controller.session should NOT be nil after the action" do
26 get 'action_with_template'
27 controller.session.should_not be_nil
30 it "specifying a partial should work with partial name only" do
31 get 'action_with_partial'
32 response.should render_template("_a_partial")
35 it "specifying a partial should work with path relative to RAILS_ROOT/app/views/" do
36 get 'action_with_partial'
37 response.should render_template("controller_spec/_a_partial")
40 it "spec should have access to flash" do
41 get 'action_with_template'
42 flash[:flash_key].should == "flash value"
45 it "spec should have access to flash values set after a session reset" do
46 get 'action_setting_flash_after_session_reset'
47 flash[:after_reset].should == "available"
50 it "spec should not have access to flash values set before a session reset" do
51 get 'action_setting_flash_before_session_reset'
52 flash[:before_reset].should_not == "available"
55 it "spec should have access to session" do
56 get 'action_with_template'
57 session[:session_key].should == "session value"
60 it "custom routes should be speccable" do
61 route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
64 it "routes should be speccable" do
65 route_for(:controller => "controller_spec", :action => "some_action").should == "/controller_spec/some_action"
68 it "exposes the assigns hash directly" do
69 get 'action_setting_the_assigns_hash'
70 assigns[:direct_assigns_key].should == :direct_assigns_key_value
74 describe "Given a controller spec for RedirectSpecController running in #{mode} mode", :behaviour_type => :controller do
75 controller_name :redirect_spec
76 integrate_views if mode == 'integration'
78 it "a redirect should ignore the absence of a template" do
79 get 'action_with_redirect_to_somewhere'
80 response.should be_redirect
81 response.redirect_url.should == "http://test.host/redirect_spec/somewhere"
82 response.should redirect_to("http://test.host/redirect_spec/somewhere")
85 it "a call to response.should redirect_to should fail if no redirect" do
86 get 'action_with_no_redirect'
88 response.redirect?.should be_true
91 response.should redirect_to("http://test.host/redirect_spec/somewhere")
92 }.should fail_with("expected redirect to \"http://test.host/redirect_spec/somewhere\", got no redirect")
96 describe "Given a controller spec running in #{mode} mode", :behaviour_type => :controller do
97 integrate_views if mode == 'integration'
98 it "a spec in a context without controller_name set should fail with a useful warning",
100 Spec::Expectations::ExpectationNotMetError,
101 /You have to declare the controller name in controller specs/
108 describe ControllerSpecController, :behaviour_type => :controller do
109 it "should not require naming the controller if describe is passed a type" do
116 describe ControllerBehaviour do
117 it "should tell you its behaviour_type is :controller" do
118 behaviour = ControllerBehaviour.new("") {}
119 behaviour.behaviour_type.should == :controller