Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 562 lines (463 sloc) 14.53 kB
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
1 require File.expand_path('../helper', __FILE__)
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
2
c630483 @sr options_test.rb => settings_test.rb
sr authored
3 class SettingsTest < Test::Unit::TestCase
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
4 setup do
af1ee6a @sr Get rid of Default
sr authored
5 @base = Sinatra.new(Sinatra::Base)
db761b8 @rkh let app_file default to the file subclassing Sinatra::Base in modular…
rkh authored
6 @base.set :environment => :foo, :app_file => nil
b1936b6 @sr Clean-up settings test
sr authored
7
af1ee6a @sr Get rid of Default
sr authored
8 @application = Sinatra.new(Sinatra::Application)
db761b8 @rkh let app_file default to the file subclassing Sinatra::Base in modular…
rkh authored
9 @application.set :environment => :foo, :app_file => nil
2fdecae @sr Add full test coverage for all options
sr authored
10 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
11
b1936b6 @sr Clean-up settings test
sr authored
12 it 'sets settings to literal values' do
97ca01d @sr Clean up options tests
sr authored
13 @base.set(:foo, 'bar')
14 assert @base.respond_to?(:foo)
15 assert_equal 'bar', @base.foo
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
16 end
17
b1936b6 @sr Clean-up settings test
sr authored
18 it 'sets settings to Procs' do
97ca01d @sr Clean up options tests
sr authored
19 @base.set(:foo, Proc.new { 'baz' })
20 assert @base.respond_to?(:foo)
21 assert_equal 'baz', @base.foo
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
22 end
23
0915274 @trans add test for using set with a block
trans authored
24 it 'sets settings using a block' do
25 @base.set(:foo){ 'baz' }
26 assert @base.respond_to?(:foo)
27 assert_equal 'baz', @base.foo
28 end
29
30c2ef8 @rtomayko set with block and value raises ArgumentError
rtomayko authored
30 it 'raises an error with a value and a block' do
31 assert_raise ArgumentError do
32 @base.set(:fiz, 'boom!'){ 'baz' }
33 end
34 assert !@base.respond_to?(:fiz)
0915274 @trans add test for using set with a block
trans authored
35 end
36
1632f24 @rkh detect whether a second argument was passed to #set correctly
rkh authored
37 it 'raises an error without value and block' do
38 assert_raise(ArgumentError) { @base.set(:fiz) }
39 assert !@base.respond_to?(:fiz)
40 end
41
42 it 'allows setting a value to the app class' do
43 @base.set :base, @base
44 assert @base.respond_to?(:base)
45 assert_equal @base, @base.base
46 end
47
48 it 'raises an error with the app class as value and a block' do
49 assert_raise ArgumentError do
50 @base.set(:fiz, @base) { 'baz' }
51 end
52 assert !@base.respond_to?(:fiz)
53 end
54
b1936b6 @sr Clean-up settings test
sr authored
55 it "sets multiple settings with a Hash" do
97ca01d @sr Clean up options tests
sr authored
56 @base.set :foo => 1234,
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
57 :bar => 'Hello World',
58 :baz => Proc.new { 'bizzle' }
97ca01d @sr Clean up options tests
sr authored
59 assert_equal 1234, @base.foo
60 assert_equal 'Hello World', @base.bar
61 assert_equal 'bizzle', @base.baz
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
62 end
63
1187a86 @sr set accepts anything responding to each
sr authored
64 it 'sets multiple settings using #each' do
65 @base.set [["foo", "bar"]]
66 assert_equal "bar", @base.foo
67 end
68
b1936b6 @sr Clean-up settings test
sr authored
69 it 'inherits settings methods when subclassed' do
97ca01d @sr Clean up options tests
sr authored
70 @base.set :foo, 'bar'
71 @base.set :biz, Proc.new { 'baz' }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
72
97ca01d @sr Clean up options tests
sr authored
73 sub = Class.new(@base)
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
74 assert sub.respond_to?(:foo)
75 assert_equal 'bar', sub.foo
76 assert sub.respond_to?(:biz)
77 assert_equal 'baz', sub.biz
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
78 end
79
b1936b6 @sr Clean-up settings test
sr authored
80 it 'overrides settings in subclass' do
97ca01d @sr Clean up options tests
sr authored
81 @base.set :foo, 'bar'
82 @base.set :biz, Proc.new { 'baz' }
83 sub = Class.new(@base)
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
84 sub.set :foo, 'bling'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
85 assert_equal 'bling', sub.foo
97ca01d @sr Clean up options tests
sr authored
86 assert_equal 'bar', @base.foo
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
87 end
88
89 it 'creates setter methods when first defined' do
97ca01d @sr Clean up options tests
sr authored
90 @base.set :foo, 'bar'
91 assert @base.respond_to?('foo=')
92 @base.foo = 'biz'
93 assert_equal 'biz', @base.foo
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
94 end
95
96 it 'creates predicate methods when first defined' do
97ca01d @sr Clean up options tests
sr authored
97 @base.set :foo, 'hello world'
98 assert @base.respond_to?(:foo?)
99 assert @base.foo?
100 @base.set :foo, nil
101 assert !@base.foo?
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
102 end
103
104 it 'uses existing setter methods if detected' do
97ca01d @sr Clean up options tests
sr authored
105 class << @base
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
106 def foo
107 @foo
108 end
109 def foo=(value)
110 @foo = 'oops'
111 end
112 end
113
97ca01d @sr Clean up options tests
sr authored
114 @base.set :foo, 'bam'
115 assert_equal 'oops', @base.foo
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
116 end
117
e9e3c85 @rkh refactor #set
rkh authored
118 it 'merges values of multiple set calls if those are hashes' do
119 @base.set :foo, :a => 1
120 sub = Class.new(@base)
121 sub.set :foo, :b => 2
122 assert_equal({:a => 1, :b => 2}, sub.foo)
123 end
124
125 it 'merging does not affect the superclass' do
126 @base.set :foo, :a => 1
127 sub = Class.new(@base)
128 sub.set :foo, :b => 2
129 assert_equal({:a => 1}, @base.foo)
130 end
131
132 it 'is possible to change a value from a hash to something else' do
133 @base.set :foo, :a => 1
134 @base.set :foo, :bar
135 assert_equal(:bar, @base.foo)
136 end
137
138 it 'merges values with values of the superclass if those are hashes' do
139 @base.set :foo, :a => 1
140 @base.set :foo, :b => 2
141 assert_equal({:a => 1, :b => 2}, @base.foo)
142 end
143
b1936b6 @sr Clean-up settings test
sr authored
144 it "sets multiple settings to true with #enable" do
97ca01d @sr Clean up options tests
sr authored
145 @base.enable :sessions, :foo, :bar
146 assert @base.sessions
147 assert @base.foo
148 assert @base.bar
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
149 end
150
b1936b6 @sr Clean-up settings test
sr authored
151 it "sets multiple settings to false with #disable" do
97ca01d @sr Clean up options tests
sr authored
152 @base.disable :sessions, :foo, :bar
153 assert !@base.sessions
154 assert !@base.foo
155 assert !@base.bar
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
156 end
ed923ca @rtomayko improve test coverage
rtomayko authored
157
df21027 @defunkt Adds a #settings method which #options is alised to.
defunkt authored
158 it 'is accessible from instances via #settings' do
1d9034f @rkh use new! rather than new for tests testing instance method
rkh authored
159 assert_equal :foo, @base.new!.settings.environment
b1936b6 @sr Clean-up settings test
sr authored
160 end
161
33affbf @rkh Add class level #settings for convenience.
rkh authored
162 it 'is accessible from class via #settings' do
163 assert_equal :foo, @base.settings.environment
164 end
165
b1936b6 @sr Clean-up settings test
sr authored
166 describe 'methodoverride' do
167 it 'is disabled on Base' do
e153415 @sr rename methodoverride setting to method_override
sr authored
168 assert ! @base.method_override?
b1936b6 @sr Clean-up settings test
sr authored
169 end
170
171 it 'is enabled on Application' do
e153415 @sr rename methodoverride setting to method_override
sr authored
172 assert @application.method_override?
b1936b6 @sr Clean-up settings test
sr authored
173 end
174
175 it 'enables MethodOverride middleware' do
e153415 @sr rename methodoverride setting to method_override
sr authored
176 @base.set :method_override, true
b1936b6 @sr Clean-up settings test
sr authored
177 @base.put('/') { 'okay' }
178 @app = @base
179 post '/', {'_method'=>'PUT'}, {}
180 assert_equal 200, status
181 assert_equal 'okay', body
182 end
e153415 @sr rename methodoverride setting to method_override
sr authored
183
184 it 'is backward compatible with methodoverride' do
185 assert ! @base.methodoverride?
186 @base.enable :methodoverride
187 assert @base.methodoverride?
188 end
df21027 @defunkt Adds a #settings method which #options is alised to.
defunkt authored
189 end
190
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
191 describe 'run' do
192 it 'is disabled on Base' do
193 assert ! @base.run?
194 end
2fdecae @sr Add full test coverage for all options
sr authored
195
b1936b6 @sr Clean-up settings test
sr authored
196 it 'is enabled on Application except in test environment' do
af1ee6a @sr Get rid of Default
sr authored
197 assert @application.run?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
198
b1936b6 @sr Clean-up settings test
sr authored
199 @application.set :environment, :test
200 assert ! @application.run?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
201 end
2fdecae @sr Add full test coverage for all options
sr authored
202 end
203
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
204 describe 'raise_errors' do
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
205 it 'is enabled on Base only in test' do
206 assert ! @base.raise_errors?
207
208 @base.set(:environment, :test)
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
209 assert @base.raise_errors?
210 end
2fdecae @sr Add full test coverage for all options
sr authored
211
af1ee6a @sr Get rid of Default
sr authored
212 it 'is enabled on Application only in test' do
213 assert ! @application.raise_errors?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
214
af1ee6a @sr Get rid of Default
sr authored
215 @application.set(:environment, :test)
216 assert @application.raise_errors?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
217 end
2fdecae @sr Add full test coverage for all options
sr authored
218 end
219
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
220 describe 'show_exceptions' do
afe0349 @rtomayko Base enable show_exceptions, dump_errors in development
rtomayko authored
221 it 'is disabled on Base except under development' do
b1936b6 @sr Clean-up settings test
sr authored
222 assert ! @base.show_exceptions?
afe0349 @rtomayko Base enable show_exceptions, dump_errors in development
rtomayko authored
223 @base.environment = :development
224 assert @base.show_exceptions?
b2ed12c @rtomayko Disable :show_exceptions on Base in all environments
rtomayko authored
225 end
226
b1936b6 @sr Clean-up settings test
sr authored
227 it 'is disabled on Application except in development' do
af1ee6a @sr Get rid of Default
sr authored
228 assert ! @application.show_exceptions?
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
229
b1936b6 @sr Clean-up settings test
sr authored
230 @application.set(:environment, :development)
231 assert @application.show_exceptions?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
232 end
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
233
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
234 it 'returns a friendly 500' do
af1ee6a @sr Get rid of Default
sr authored
235 klass = Sinatra.new(Sinatra::Application)
97ca01d @sr Clean up options tests
sr authored
236 mock_app(klass) {
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
237 enable :show_exceptions
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
238
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
239 get '/' do
240 raise StandardError
241 end
242 }
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
243
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
244 get '/'
245 assert_equal 500, status
246 assert body.include?("StandardError")
01b5f65 @sr options => settings in ShowExceptions
sr authored
247 assert body.include?("<code>show_exceptions</code> setting")
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
248 end
af2de4e @rkh Only run error handlers if show_excetions is set to :after_handler, n…
rkh authored
249
250 it 'does not override app-specified error handling when set to :after_handler' do
67ae9be @rkh refactor error handling (removes one instance_eval)
rkh authored
251 ran = false
252 mock_app do
af2de4e @rkh Only run error handlers if show_excetions is set to :after_handler, n…
rkh authored
253 set :show_exceptions, :after_handler
67ae9be @rkh refactor error handling (removes one instance_eval)
rkh authored
254 error(RuntimeError) { ran = true }
255 get('/') { raise RuntimeError }
256 end
257
732bc75 @pangel Bugfix. show_exceptions used to override app-specified exceptions (er…
pangel authored
258 get '/'
259 assert_equal 500, status
67ae9be @rkh refactor error handling (removes one instance_eval)
rkh authored
260 assert ran
261 end
262
263 it 'does catch any other exceptions when set to :after_handler' do
264 ran = false
265 mock_app do
266 set :show_exceptions, :after_handler
267 error(RuntimeError) { ran = true }
268 get('/') { raise ArgumentError }
269 end
732bc75 @pangel Bugfix. show_exceptions used to override app-specified exceptions (er…
pangel authored
270
67ae9be @rkh refactor error handling (removes one instance_eval)
rkh authored
271 get '/'
272 assert_equal 500, status
273 assert !ran
732bc75 @pangel Bugfix. show_exceptions used to override app-specified exceptions (er…
pangel authored
274 end
2fdecae @sr Add full test coverage for all options
sr authored
275 end
276
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
277 describe 'dump_errors' do
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
278 it 'is disabled on Base in test' do
279 @base.environment = :test
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
280 assert ! @base.dump_errors?
afe0349 @rtomayko Base enable show_exceptions, dump_errors in development
rtomayko authored
281 @base.environment = :development
282 assert @base.dump_errors?
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
283 @base.environment = :production
284 assert @base.dump_errors?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
285 end
2fdecae @sr Add full test coverage for all options
sr authored
286
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
287 it 'dumps exception with backtrace to rack.errors' do
af1ee6a @sr Get rid of Default
sr authored
288 klass = Sinatra.new(Sinatra::Application)
97ca01d @sr Clean up options tests
sr authored
289
290 mock_app(klass) {
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
291 enable :dump_errors
97ca01d @sr Clean up options tests
sr authored
292 disable :raise_errors
2fdecae @sr Add full test coverage for all options
sr authored
293
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
294 error do
295 error = @env['rack.errors'].instance_variable_get(:@error)
296 error.rewind
2fdecae @sr Add full test coverage for all options
sr authored
297
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
298 error.read
299 end
2fdecae @sr Add full test coverage for all options
sr authored
300
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
301 get '/' do
302 raise
303 end
304 }
2fdecae @sr Add full test coverage for all options
sr authored
305
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
306 get '/'
c630483 @sr options_test.rb => settings_test.rb
sr authored
307 assert body.include?("RuntimeError") && body.include?("settings_test.rb")
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
308 end
fd74972 @rkh do not dump 404 traces
rkh authored
309
310 it 'does not dump 404 errors' do
311 klass = Sinatra.new(Sinatra::Application)
312
313 mock_app(klass) {
314 enable :dump_errors
315 disable :raise_errors
316
317 error do
318 error = @env['rack.errors'].instance_variable_get(:@error)
319 error.rewind
320
321 error.read
322 end
323
324 get '/' do
325 raise Sinatra::NotFound
326 end
327 }
328
329 get '/'
330 assert !body.include?("NotFound") && !body.include?("settings_test.rb")
331 end
2fdecae @sr Add full test coverage for all options
sr authored
332 end
333
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
334 describe 'sessions' do
335 it 'is disabled on Base' do
336 assert ! @base.sessions?
337 end
2fdecae @sr Add full test coverage for all options
sr authored
338
af1ee6a @sr Get rid of Default
sr authored
339 it 'is disabled on Application' do
340 assert ! @application.sessions?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
341 end
2fdecae @sr Add full test coverage for all options
sr authored
342 end
343
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
344 describe 'logging' do
345 it 'is disabled on Base' do
346 assert ! @base.logging?
347 end
2fdecae @sr Add full test coverage for all options
sr authored
348
b1936b6 @sr Clean-up settings test
sr authored
349 it 'is enabled on Application except in test environment' do
af1ee6a @sr Get rid of Default
sr authored
350 assert @application.logging?
2fdecae @sr Add full test coverage for all options
sr authored
351
af1ee6a @sr Get rid of Default
sr authored
352 @application.set :environment, :test
353 assert ! @application.logging
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
354 end
2fdecae @sr Add full test coverage for all options
sr authored
355 end
356
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
357 describe 'static' do
de6d6d6 @rtomayko Base enables static by default if public is set and exists
rtomayko authored
358 it 'is disabled on Base by default' do
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
359 assert ! @base.static?
360 end
2fdecae @sr Add full test coverage for all options
sr authored
361
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
362 it 'is enabled on Base when public_folder is set and exists' do
de6d6d6 @rtomayko Base enables static by default if public is set and exists
rtomayko authored
363 @base.set :environment, :development
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
364 @base.set :public_folder, File.dirname(__FILE__)
de6d6d6 @rtomayko Base enables static by default if public is set and exists
rtomayko authored
365 assert @base.static?
366 end
367
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
368 it 'is enabled on Base when root is set and root/public_folder exists' do
de6d6d6 @rtomayko Base enables static by default if public is set and exists
rtomayko authored
369 @base.set :environment, :development
370 @base.set :root, File.dirname(__FILE__)
371 assert @base.static?
372 end
373
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
374 it 'is disabled on Application by default' do
375 assert ! @application.static?
376 end
377
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
378 it 'is enabled on Application when public_folder is set and exists' do
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
379 @application.set :environment, :development
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
380 @application.set :public_folder, File.dirname(__FILE__)
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
381 assert @application.static?
382 end
383
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
384 it 'is enabled on Application when root is set and root/public_folder exists' do
12ee3ba @rtomayko raise_errors is disabled by default except in test environment
rtomayko authored
385 @application.set :environment, :development
386 @application.set :root, File.dirname(__FILE__)
af1ee6a @sr Get rid of Default
sr authored
387 assert @application.static?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
388 end
2d89712 @rkh add (failing) tests for Module#public, related to #301
rkh authored
389
390 it 'is possible to use Module#public' do
391 @base.send(:define_method, :foo) { }
392 @base.send(:private, :foo)
2f5816e @timfel explicitely use public_method_defined instead of just method_defined
timfel authored
393 assert !@base.public_method_defined?(:foo)
2d89712 @rkh add (failing) tests for Module#public, related to #301
rkh authored
394 @base.send(:public, :foo)
2f5816e @timfel explicitely use public_method_defined instead of just method_defined
timfel authored
395 assert @base.public_method_defined?(:foo)
2d89712 @rkh add (failing) tests for Module#public, related to #301
rkh authored
396 end
397
398 it 'is possible to use the keyword public in a sinatra app' do
399 app = Sinatra.new do
400 private
401 def priv; end
402 public
403 def pub; end
404 end
2f5816e @timfel explicitely use public_method_defined instead of just method_defined
timfel authored
405 assert !app.public_method_defined?(:priv)
406 assert app.public_method_defined?(:pub)
2d89712 @rkh add (failing) tests for Module#public, related to #301
rkh authored
407 end
2fdecae @sr Add full test coverage for all options
sr authored
408 end
409
849a5a9 using -b over -h option from cli for bind address
Blake Mizerany authored
410 describe 'bind' do
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
411 it 'defaults to 0.0.0.0' do
849a5a9 using -b over -h option from cli for bind address
Blake Mizerany authored
412 assert_equal '0.0.0.0', @base.bind
413 assert_equal '0.0.0.0', @application.bind
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
414 end
2fdecae @sr Add full test coverage for all options
sr authored
415 end
416
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
417 describe 'port' do
418 it 'defaults to 4567' do
419 assert_equal 4567, @base.port
af1ee6a @sr Get rid of Default
sr authored
420 assert_equal 4567, @application.port
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
421 end
2fdecae @sr Add full test coverage for all options
sr authored
422 end
423
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
424 describe 'server' do
6ec5234 @rkh be smarter about servers
rkh authored
425 it 'includes webrick' do
426 assert @base.server.include?('webrick')
427 assert @application.server.include?('webrick')
428 end
429
430 it 'includes puma' do
431 assert @base.server.include?('puma')
432 assert @application.server.include?('puma')
433 end
434
435 it 'includes thin' do
436 next if RUBY_ENGINE == 'jruby'
437 assert @base.server.include?('thin')
438 assert @application.server.include?('thin')
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
439 end
2fdecae @sr Add full test coverage for all options
sr authored
440 end
441
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
442 describe 'app_file' do
db761b8 @rkh let app_file default to the file subclassing Sinatra::Base in modular…
rkh authored
443 it 'is nil for base classes' do
444 assert_nil Sinatra::Base.app_file
445 assert_nil Sinatra::Application.app_file
446 end
447
448 it 'defaults to the file subclassing' do
37e7d43 @timfel MagLev doesn't #expand __FILE__ like it should
timfel authored
449 assert_equal File.expand_path(__FILE__), Sinatra.new.app_file
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
450 end
2fdecae @sr Add full test coverage for all options
sr authored
451 end
452
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
453 describe 'root' do
454 it 'is nil if app_file is not set' do
455 assert @base.root.nil?
af1ee6a @sr Get rid of Default
sr authored
456 assert @application.root.nil?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
457 end
2fdecae @sr Add full test coverage for all options
sr authored
458
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
459 it 'is equal to the expanded basename of app_file' do
460 @base.app_file = __FILE__
461 assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
462
af1ee6a @sr Get rid of Default
sr authored
463 @application.app_file = __FILE__
464 assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
465 end
2fdecae @sr Add full test coverage for all options
sr authored
466 end
467
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
468 describe 'views' do
469 it 'is nil if root is not set' do
470 assert @base.views.nil?
af1ee6a @sr Get rid of Default
sr authored
471 assert @application.views.nil?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
472 end
473
474 it 'is set to root joined with views/' do
475 @base.root = File.dirname(__FILE__)
476 assert_equal File.dirname(__FILE__) + "/views", @base.views
477
af1ee6a @sr Get rid of Default
sr authored
478 @application.root = File.dirname(__FILE__)
479 assert_equal File.dirname(__FILE__) + "/views", @application.views
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
480 end
2fdecae @sr Add full test coverage for all options
sr authored
481 end
482
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
483 describe 'public_folder' do
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
484 it 'is nil if root is not set' do
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
485 assert @base.public_folder.nil?
486 assert @application.public_folder.nil?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
487 end
488
489 it 'is set to root joined with public/' do
490 @base.root = File.dirname(__FILE__)
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
491 assert_equal File.dirname(__FILE__) + "/public", @base.public_folder
2fdecae @sr Add full test coverage for all options
sr authored
492
af1ee6a @sr Get rid of Default
sr authored
493 @application.root = File.dirname(__FILE__)
d1ab58d @rkh rename public to public_folder, fixes #301
rkh authored
494 assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
495 end
2fdecae @sr Add full test coverage for all options
sr authored
496 end
497
3054dbc @gnandretta alias public_folder as public_dir
gnandretta authored
498 describe 'public_dir' do
499 it 'is an alias for public_folder' do
500 @base.public_dir = File.dirname(__FILE__)
501 assert_equal File.dirname(__FILE__), @base.public_dir
502 assert_equal @base.public_folder, @base.public_dir
503
504 @application.public_dir = File.dirname(__FILE__)
505 assert_equal File.dirname(__FILE__), @application.public_dir
506 assert_equal @application.public_folder, @application.public_dir
507 end
508 end
509
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
510 describe 'lock' do
511 it 'is disabled by default' do
512 assert ! @base.lock?
b1936b6 @sr Clean-up settings test
sr authored
513 assert ! @application.lock?
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
514 end
2fdecae @sr Add full test coverage for all options
sr authored
515 end
1f1e58e @rkh add rack-protection, fixes #310
rkh authored
516
517 describe 'protection' do
518 class MiddlewareTracker < Rack::Builder
519 def self.track
520 Rack.send :remove_const, :Builder
521 Rack.const_set :Builder, MiddlewareTracker
522 MiddlewareTracker.used.clear
523 yield
524 ensure
525 Rack.send :remove_const, :Builder
526 Rack.const_set :Builder, MiddlewareTracker.superclass
527 end
528
529 def self.used
530 @used ||= []
531 end
532
533 def use(middleware, *)
534 MiddlewareTracker.used << middleware
535 super
536 end
537 end
538
539 it 'sets up Rack::Protection' do
540 MiddlewareTracker.track do
541 Sinatra::Base.new
542 assert_include MiddlewareTracker.used, Rack::Protection
543 end
544 end
545
546 it 'sets up Rack::Protection::PathTraversal' do
547 MiddlewareTracker.track do
548 Sinatra::Base.new
549 assert_include MiddlewareTracker.used, Rack::Protection::PathTraversal
550 end
551 end
552
553 it 'does not set up Rack::Protection::PathTraversal when disabling it' do
554 MiddlewareTracker.track do
555 Sinatra.new { set :protection, :except => :path_traversal }.new
556 assert_include MiddlewareTracker.used, Rack::Protection
557 assert !MiddlewareTracker.used.include?(Rack::Protection::PathTraversal)
558 end
559 end
560 end
2fdecae @sr Add full test coverage for all options
sr authored
561 end
Something went wrong with that request. Please try again.