Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 234 lines (157 sloc) 4.278 kB
520ac2e Haml
Blake Mizerany authored
1 require File.dirname(__FILE__) + '/helper'
2
3 context "Haml" do
4
5 setup do
6 Sinatra.application = nil
7 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
8
520ac2e Haml
Blake Mizerany authored
9 context "without layouts" do
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
10
520ac2e Haml
Blake Mizerany authored
11 setup do
12 Sinatra.application = nil
13 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
14
520ac2e Haml
Blake Mizerany authored
15 specify "should render" do
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
16
520ac2e Haml
Blake Mizerany authored
17 get '/no_layout' do
18 haml '== #{1+1}'
19 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
20
520ac2e Haml
Blake Mizerany authored
21 get_it '/no_layout'
22 should.be.ok
23 body.should == "2\n"
24
25 end
26 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
27
520ac2e Haml
Blake Mizerany authored
28 context "with layouts" do
29
30 setup do
31 Sinatra.application = nil
32 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
33
520ac2e Haml
Blake Mizerany authored
34 specify "can be inline" do
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
35
520ac2e Haml
Blake Mizerany authored
36 layout do
7d5bc1f Haml & Erb redo
Blake Mizerany authored
37 '== This is #{yield}!'
520ac2e Haml
Blake Mizerany authored
38 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
39
520ac2e Haml
Blake Mizerany authored
40 get '/lay' do
41 haml 'Blake'
42 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
43
520ac2e Haml
Blake Mizerany authored
44 get_it '/lay'
45 should.be.ok
46 body.should.equal "This is Blake\n!\n"
47
48 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
49
520ac2e Haml
Blake Mizerany authored
50 specify "can use named layouts" do
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
51
520ac2e Haml
Blake Mizerany authored
52 layout :pretty do
7d5bc1f Haml & Erb redo
Blake Mizerany authored
53 '%h1== #{yield}'
520ac2e Haml
Blake Mizerany authored
54 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
55
520ac2e Haml
Blake Mizerany authored
56 get '/pretty' do
57 haml 'Foo', :layout => :pretty
58 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
59
520ac2e Haml
Blake Mizerany authored
60 get '/not_pretty' do
61 haml 'Bar'
62 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
63
520ac2e Haml
Blake Mizerany authored
64 get_it '/pretty'
65 body.should.equal "<h1>Foo</h1>\n"
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
66
520ac2e Haml
Blake Mizerany authored
67 get_it '/not_pretty'
68 body.should.equal "Bar\n"
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
69
520ac2e Haml
Blake Mizerany authored
70 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
71
520ac2e Haml
Blake Mizerany authored
72 specify "can be read from a file if they're not inlined" do
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
73
520ac2e Haml
Blake Mizerany authored
74 get '/foo' do
75 @title = 'Welcome to the Hello Program'
76 haml 'Blake', :layout => :foo_layout,
77 :views_directory => File.dirname(__FILE__) + "/views"
78 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
79
520ac2e Haml
Blake Mizerany authored
80 get_it '/foo'
81 body.should.equal "Welcome to the Hello Program\nHi Blake\n"
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
82
520ac2e Haml
Blake Mizerany authored
83 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
84
7d5bc1f Haml & Erb redo
Blake Mizerany authored
85 specify "can be read from file and layout from text" do
86 get '/foo' do
87 haml 'Test', :layout => '== Foo #{yield}'
88 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
89
7d5bc1f Haml & Erb redo
Blake Mizerany authored
90 get_it '/foo'
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
91
7d5bc1f Haml & Erb redo
Blake Mizerany authored
92 body.should.equal "Foo Test\n"
93 end
520ac2e Haml
Blake Mizerany authored
94
95 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
96
7d5bc1f Haml & Erb redo
Blake Mizerany authored
97 context "Templates (in general)" do
98
ccbb070 FIX: Render without layout
Blake Mizerany authored
99 setup do
100 Sinatra.application = nil
101 end
102
7d5bc1f Haml & Erb redo
Blake Mizerany authored
103 specify "are read from files if Symbols" do
104
105 get '/from_file' do
106 @name = 'Alena'
107 haml :foo, :views_directory => File.dirname(__FILE__) + "/views"
108 end
109
110 get_it '/from_file'
111
112 body.should.equal "You rock Alena!\n"
113
114 end
115
116 specify "use layout.ext by default if available" do
117
ccbb070 FIX: Render without layout
Blake Mizerany authored
118 get '/' do
7d5bc1f Haml & Erb redo
Blake Mizerany authored
119 haml :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
120 end
121
ccbb070 FIX: Render without layout
Blake Mizerany authored
122 get_it '/'
7d5bc1f Haml & Erb redo
Blake Mizerany authored
123 should.be.ok
124 body.should.equal "x This is foo!\n x\n"
125
126 end
127
ccbb070 FIX: Render without layout
Blake Mizerany authored
128 specify "renders without layout" do
129
130 get '/' do
131 haml :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
132 end
133
134 get_it '/'
135 should.be.ok
136 body.should.equal "<h1>No Layout!</h1>\n"
137
138 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
139
898b36e @bmizerany allow user to prevent layout render
bmizerany authored
140 specify "can render with no layout" do
141 layout do
142 "X\n= yield\nX"
143 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
144
898b36e @bmizerany allow user to prevent layout render
bmizerany authored
145 get '/' do
146 haml 'blake', :layout => false
147 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
148
898b36e @bmizerany allow user to prevent layout render
bmizerany authored
149 get_it '/'
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
150
898b36e @bmizerany allow user to prevent layout render
bmizerany authored
151 body.should.equal "blake\n"
152 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
153
ccbb070 FIX: Render without layout
Blake Mizerany authored
154 specify "raises error if template not found" do
155 get '/' do
156 haml :not_found
157 end
158
159 lambda { get_it '/' }.should.raise(Errno::ENOENT)
160 end
161
6bda16b @bmizerany added `template` to DSL
bmizerany authored
162 specify "use layout.ext by default if available" do
163
164 template :foo do
165 'asdf'
166 end
167
168 get '/' do
169 haml :foo, :layout => false,
170 :views_directory => File.dirname(__FILE__) + "/views/layout_test"
171 end
172
173 get_it '/'
174 should.be.ok
175 body.should.equal "asdf\n"
176
177 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
178
7d5bc1f Haml & Erb redo
Blake Mizerany authored
179 end
180
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
181 describe 'Options passed to the HAML interpreter' do
182 setup do
183 Sinatra.application = nil
184 end
185
186 specify 'are empty be default' do
187
188 get '/' do
189 haml 'foo'
190 end
191
192 Haml::Engine.expects(:new).with('foo', {}).returns(stub(:render => 'foo'))
193
194 get_it '/'
195 should.be.ok
196
197 end
198
199 specify 'can be configured by passing :options to haml' do
200
201 get '/' do
202 haml 'foo', :options => {:format => :html4}
203 end
204
205 Haml::Engine.expects(:new).with('foo', {:format => :html4}).returns(stub(:render => 'foo'))
206
207 get_it '/'
208 should.be.ok
209
210 end
211
212 specify 'can be configured using set_option :haml' do
213
214 configure do
215 set_option :haml, :format => :html4,
216 :escape_html => true
217 end
218
219 get '/' do
220 haml 'foo'
221 end
222
223 Haml::Engine.expects(:new).with('foo', {:format => :html4,
224 :escape_html => true}).returns(stub(:render => 'foo'))
225
226 get_it '/'
227 should.be.ok
228
229 end
230
231 end
232
520ac2e Haml
Blake Mizerany authored
233 end
Something went wrong with that request. Please try again.