Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec_on_rails / spec / rails / dsl / controller_spec_spec.rb
blob95443c934963675e8ffb1e4fa79375bd555ee8a5
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'
8   
9     it "session should be the same object as controller session" do
10       get 'action_with_template'
11       session.should equal(controller.session)
12     end
13   
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)
18     end
19   
20     it "controller.session should NOT be nil before the action" do
21       controller.session.should_not be_nil
22       get 'action_with_template'
23     end
24     
25     it "controller.session should NOT be nil after the action" do
26       get 'action_with_template'
27       controller.session.should_not be_nil
28     end
29     
30     it "specifying a partial should work with partial name only" do
31       get 'action_with_partial'
32       response.should render_template("_a_partial")
33     end
34     
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")
38     end
39     
40     it "spec should have access to flash" do
41       get 'action_with_template'
42       flash[:flash_key].should == "flash value"
43     end
44     
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"
48     end
49     
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"
53     end
55     it "spec should have access to session" do
56       get 'action_with_template'
57       session[:session_key].should == "session value"
58     end
60     it "custom routes should be speccable" do
61       route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
62     end
64     it "routes should be speccable" do
65       route_for(:controller => "controller_spec", :action => "some_action").should == "/controller_spec/some_action"
66     end
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
71     end
72   end
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")
83     end
84     
85     it "a call to response.should redirect_to should fail if no redirect" do
86       get 'action_with_no_redirect'
87       lambda {
88         response.redirect?.should be_true
89       }.should fail
90       lambda {
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")
93     end
94   end
95   
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",
99       :should_raise => [
100         Spec::Expectations::ExpectationNotMetError,
101         /You have to declare the controller name in controller specs/
102       ] do
103     end
104   end
105   
108 describe ControllerSpecController, :behaviour_type => :controller do
109   it "should not require naming the controller if describe is passed a type" do
110   end
113 module Spec
114   module Rails
115     module DSL
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
120         end
121       end
122     end
123   end