Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec_on_rails / spec / rails / matchers / render_spec.rb
blobbc64358b889b3eff8d8566e04cfc9e549cff699f
1 require File.dirname(__FILE__) + '/../../spec_helper'
3 ['isolation','integration'].each do |mode|
4   describe "response.should render_template (in #{mode} mode)",
5     :behaviour_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
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 symbol" do
22       post 'some_action'
23       response.should render_template(:some_action)
24     end
26     it "should match an rjs template" do
27       xhr :post, 'some_action'
28       if ActionView::Base.const_defined?('DEFAULT_TEMPLATE_HANDLER_PREFERENCE')
29         response.should render_template('render_spec/some_action')
30       else
31         response.should render_template('render_spec/some_action.rjs')
32       end
33     end
35     it "should fail on the wrong extension (given rhtml)" do
36       get 'some_action'
37       lambda {
38         response.should render_template('render_spec/some_action.rjs')
39       }.should fail_with("expected \"render_spec/some_action.rjs\", got \"render_spec/some_action\"")
40     end
42     it "should match a partial template (simple path)" do
43       get 'action_with_partial'
44       response.should render_template("_a_partial")
45     end
47     it "should match a partial template (complex path)" do
48       get 'action_with_partial'
49       response.should render_template("render_spec/_a_partial")
50     end
52     it "should fail when the wrong template is rendered" do
53       post 'some_action'
54       lambda do
55         response.should render_template('non_existent_template')
56       end.should fail_with("expected \"non_existent_template\", got \"some_action\"")
57     end
59     it "should fail when TEXT is rendered" do
60       post 'text_action'
61       lambda do
62         response.should render_template('some_action')
63       end.should fail_with("expected \"some_action\", got nil")
64     end
65   end
67   describe "response.should have_text (in #{mode} mode)",
68     :behaviour_type => :controller do
69     controller_name :render_spec
70     if mode == 'integration'
71       integrate_views
72     end
74     it "should pass with exactly matching text" do
75       post 'text_action'
76       response.should have_text("this is the text for this action")
77     end
79     it "should pass with matching text (using Regexp)" do
80       post 'text_action'
81       response.should have_text(/is the text/)
82     end
84     it "should fail with matching text" do
85       post 'text_action'
86       lambda {
87         response.should have_text("this is NOT the text for this action")
88       }.should fail_with("expected \"this is NOT the text for this action\", got \"this is the text for this action\"")
89     end
91     it "should fail when a template is rendered" do
92       post 'some_action'
93       lambda {
94         response.should have_text("this is the text for this action")
95       }.should fail_with(/expected \"this is the text for this action\", got .*/)
96     end
97   end
99   describe "response.should_not have_text (in #{mode} mode)",
100     :behaviour_type => :controller do
101     controller_name :render_spec
102     if mode == 'integration'
103       integrate_views
104     end
106     it "should pass with exactly matching text" do
107       post 'text_action'
108       response.should_not have_text("the accordian guy")
109     end
110   end