Notify user of error if DSL error
[sinatra.git] / test / layouts_test.rb
blob890efc529165e6dc4a83c1f6f3a17336b45e0029
1 require File.dirname(__FILE__) + '/helper'
3 context "Layouts (in general)" do
4   
5   setup do
6     Sinatra.application = nil
7   end
8   
9   specify "can be inline" do
10     
11     layout do
12       %Q{This is #{@content}!}
13     end
14     
15     get '/lay' do
16       render 'Blake'
17     end
18     
19     get_it '/lay'
20     should.be.ok
21     body.should.equal 'This is Blake!'
23   end
24   
25   specify "can use named layouts" do
26     
27     layout :pretty do
28       %Q{<h1>#{@content}</h1>}
29     end
30         
31     get '/pretty' do
32       render 'Foo', :layout => :pretty
33     end
34     
35     get '/not_pretty' do
36       render 'Bar'
37     end
38     
39     get_it '/pretty'
40     body.should.equal '<h1>Foo</h1>'
41     
42     get_it '/not_pretty'
43     body.should.equal 'Bar'
44     
45   end
46   
47   specify "can be read from a file if they're not inlined" do
48     
49     get '/foo' do
50       @title = 'Welcome to the Hello Program'
51       render 'Blake', :layout => :foo_layout, 
52                       :views_directory => File.dirname(__FILE__) + "/views"
53     end
54     
55     get_it '/foo'
56     body.should.equal "Welcome to the Hello Program\nHi Blake\n"
57     
58   end
59   
60 end