/
builder_test.rb
101 lines (66 loc) · 1.83 KB
/
builder_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require File.dirname(__FILE__) + '/helper'
context "Builder" do
setup do
Sinatra.application = nil
end
context "without layouts" do
setup do
Sinatra.application = nil
end
specify "should render" do
get '/no_layout' do
builder 'xml.instruct!'
end
get_it '/no_layout'
should.be.ok
body.should == %(<?xml version="1.0" encoding="UTF-8"?>\n)
end
specify "should render inline block" do
get '/no_layout_and_inlined' do
@name = "Frank & Mary"
builder do |xml|
xml.couple @name
end
end
get_it '/no_layout_and_inlined'
should.be.ok
body.should == %(<couple>Frank & Mary</couple>\n)
end
end
context "Templates (in general)" do
setup do
Sinatra.application = nil
end
specify "are read from files if Symbols" do
get '/from_file' do
@name = 'Blue'
builder :foo, :views_directory => File.dirname(__FILE__) + "/views"
end
get_it '/from_file'
should.be.ok
body.should.equal %(<exclaim>You rock Blue!</exclaim>\n)
end
specify "use layout.ext by default if available" do
get '/' do
builder :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end
get_it '/'
should.be.ok
body.should.equal "<layout>\n<this>is foo!</this>\n</layout>\n"
end
specify "renders without layout" do
get '/' do
builder :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
end
get_it '/'
should.be.ok
body.should.equal "<foo>No Layout!</foo>\n"
end
specify "raises error if template not found" do
get '/' do
builder :not_found
end
lambda { get_it '/' }.should.raise(Errno::ENOENT)
end
end
end