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'
11 it "should match a simple path" do
13 response.should render_template('some_action')
16 it "should match a less simple path" do
18 response.should render_template('render_spec/some_action')
21 it "should match a symbol" do
23 response.should render_template(:some_action)
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')
31 response.should render_template('render_spec/some_action.rjs')
35 it "should fail on the wrong extension (given rhtml)" do
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\"")
42 it "should match a partial template (simple path)" do
43 get 'action_with_partial'
44 response.should render_template("_a_partial")
47 it "should match a partial template (complex path)" do
48 get 'action_with_partial'
49 response.should render_template("render_spec/_a_partial")
52 it "should fail when the wrong template is rendered" do
55 response.should render_template('non_existent_template')
56 end.should fail_with("expected \"non_existent_template\", got \"some_action\"")
59 it "should fail when TEXT is rendered" do
62 response.should render_template('some_action')
63 end.should fail_with("expected \"some_action\", got nil")
67 describe "response.should have_text (in #{mode} mode)",
68 :behaviour_type => :controller do
69 controller_name :render_spec
70 if mode == 'integration'
74 it "should pass with exactly matching text" do
76 response.should have_text("this is the text for this action")
79 it "should pass with matching text (using Regexp)" do
81 response.should have_text(/is the text/)
84 it "should fail with matching text" do
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\"")
91 it "should fail when a template is rendered" do
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 .*/)
99 describe "response.should_not have_text (in #{mode} mode)",
100 :behaviour_type => :controller do
101 controller_name :render_spec
102 if mode == 'integration'
106 it "should pass with exactly matching text" do
108 response.should_not have_text("the accordian guy")