Syd-sinatra 0.3.2 → 0.9.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +40 -0
- data/CHANGES +189 -0
- data/README.rdoc +148 -119
- data/Rakefile +34 -10
- data/{test → compat}/app_test.rb +11 -10
- data/{test → compat}/application_test.rb +21 -5
- data/compat/builder_test.rb +101 -0
- data/compat/erb_test.rb +136 -0
- data/{test → compat}/events_test.rb +16 -3
- data/compat/filter_test.rb +30 -0
- data/compat/haml_test.rb +233 -0
- data/compat/helper.rb +30 -0
- data/compat/mapped_error_test.rb +72 -0
- data/{test → compat}/pipeline_test.rb +9 -4
- data/compat/sass_test.rb +57 -0
- data/{test → compat}/streaming_test.rb +4 -1
- data/lib/sinatra/base.rb +843 -0
- data/lib/sinatra/compat.rb +239 -0
- data/lib/sinatra/main.rb +48 -0
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +7 -8
- data/lib/sinatra/test/spec.rb +3 -4
- data/lib/sinatra/test/unit.rb +3 -5
- data/lib/sinatra/test.rb +114 -0
- data/lib/sinatra.rb +6 -1468
- data/sinatra.gemspec +68 -35
- data/test/base_test.rb +68 -0
- data/test/builder_test.rb +50 -87
- data/test/data/reload_app_file.rb +3 -0
- data/test/erb_test.rb +38 -124
- data/test/filter_test.rb +65 -20
- data/test/haml_test.rb +51 -216
- data/test/helper.rb +23 -5
- data/test/helpers_test.rb +361 -0
- data/test/mapped_error_test.rb +137 -49
- data/test/middleware_test.rb +58 -0
- data/test/options_test.rb +97 -0
- data/test/reload_test.rb +61 -0
- data/test/request_test.rb +18 -0
- data/test/result_test.rb +88 -0
- data/test/routing_test.rb +391 -0
- data/test/sass_test.rb +27 -48
- data/test/sinatra_test.rb +13 -0
- data/test/static_test.rb +57 -0
- data/test/templates_test.rb +88 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.test +1 -0
- metadata +79 -47
- data/ChangeLog +0 -78
- data/lib/sinatra/test/methods.rb +0 -76
- data/test/event_context_test.rb +0 -15
- /data/{test → compat}/custom_error_test.rb +0 -0
- /data/{test → compat}/public/foo.xml +0 -0
- /data/{test → compat}/sessions_test.rb +0 -0
- /data/{test → compat}/sym_params_test.rb +0 -0
- /data/{test → compat}/template_test.rb +0 -0
- /data/{test → compat}/use_in_file_templates_test.rb +0 -0
- /data/{test → compat}/views/foo.builder +0 -0
- /data/{test → compat}/views/foo.erb +0 -0
- /data/{test → compat}/views/foo.haml +0 -0
- /data/{test → compat}/views/foo.sass +0 -0
- /data/{test → compat}/views/foo_layout.erb +0 -0
- /data/{test → compat}/views/foo_layout.haml +0 -0
- /data/{test → compat}/views/layout_test/foo.builder +0 -0
- /data/{test → compat}/views/layout_test/foo.erb +0 -0
- /data/{test → compat}/views/layout_test/foo.haml +0 -0
- /data/{test → compat}/views/layout_test/foo.sass +0 -0
- /data/{test → compat}/views/layout_test/layout.builder +0 -0
- /data/{test → compat}/views/layout_test/layout.erb +0 -0
- /data/{test → compat}/views/layout_test/layout.haml +0 -0
- /data/{test → compat}/views/layout_test/layout.sass +0 -0
- /data/{test → compat}/views/no_layout/no_layout.builder +0 -0
- /data/{test → compat}/views/no_layout/no_layout.haml +0 -0
- /data/{images → lib/sinatra/images}/404.png +0 -0
- /data/{images → lib/sinatra/images}/500.png +0 -0
data/README.rdoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= Sinatra
|
2
2
|
|
3
3
|
Sinatra is a DSL for quickly creating web-applications in Ruby with minimal
|
4
|
-
effort
|
5
|
-
|
6
|
-
== Sample App
|
4
|
+
effort:
|
7
5
|
|
8
6
|
# myapp.rb
|
9
7
|
require 'rubygems'
|
@@ -32,78 +30,80 @@ Run with <tt>ruby myapp.rb</tt> and view at <tt>http://localhost:4567</tt>
|
|
32
30
|
.. annihilate something ..
|
33
31
|
end
|
34
32
|
|
35
|
-
head '/' do
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
NOTE: <tt>put</tt> and <tt>delete</tt> are also triggered when a
|
40
|
-
<tt>_method</tt> parameter is set to PUT or DELETE and the HTTP request method
|
41
|
-
is POST
|
42
|
-
|
43
33
|
== Routes
|
44
34
|
|
45
35
|
Routes are matched based on the order of declaration. The first route that
|
46
36
|
matches the request is invoked.
|
47
37
|
|
48
|
-
|
38
|
+
Basic routes:
|
49
39
|
|
50
40
|
get '/hi' do
|
51
41
|
...
|
52
42
|
end
|
53
43
|
|
54
|
-
|
44
|
+
Route patterns may include named parameters, accessible via the
|
45
|
+
<tt>params</tt> hash:
|
55
46
|
|
56
47
|
get '/:name' do
|
57
|
-
# matches /
|
48
|
+
# matches "GET /foo" and "GET /bar"
|
49
|
+
# params[:name] is 'foo' or 'bar'
|
50
|
+
"Hello #{params[:name]}!"
|
58
51
|
end
|
59
52
|
|
60
|
-
|
53
|
+
Route patterns may also include splat (or wildcard) parameters, accessible
|
54
|
+
via the <tt>params[:splat]</tt> array.
|
61
55
|
|
62
56
|
get '/say/*/to/*' do
|
63
57
|
# matches /say/hello/to/world
|
64
|
-
params[
|
58
|
+
params[:splat] # => ["hello", "world"]
|
65
59
|
end
|
66
60
|
|
67
61
|
get '/download/*.*' do
|
68
62
|
# matches /download/path/to/file.xml
|
69
|
-
params[
|
63
|
+
params[:splat] # => ["path/to/file", "xml"]
|
64
|
+
end
|
65
|
+
|
66
|
+
Route matching with Regular Expressions:
|
67
|
+
|
68
|
+
get %r{/hello/([\w]+)} do
|
69
|
+
"Hello, #{params[:captures].first}!"
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
Routes may include a variety of matching conditions, such as the user agent:
|
73
73
|
|
74
74
|
get '/foo', :agent => /Songbird (\d\.\d)[\d\/]*?/ do
|
75
75
|
"You're using Songbird version #{params[:agent][0]}"
|
76
76
|
end
|
77
77
|
|
78
78
|
get '/foo' do
|
79
|
-
#
|
79
|
+
# Matches non-songbird browsers
|
80
80
|
end
|
81
81
|
|
82
|
-
== Static
|
82
|
+
== Static Files
|
83
83
|
|
84
|
-
|
84
|
+
Static files are served from the <tt>./public</tt> directory. You can specify
|
85
|
+
a different location by setting the <tt>:public</tt> option:
|
85
86
|
|
86
|
-
|
87
|
-
\ public
|
87
|
+
set :public, File.dirname(__FILE__) + '/static'
|
88
88
|
|
89
|
-
|
90
|
-
request ends. Otherwise, Sinatra will look for an event that matches the
|
91
|
-
path.
|
89
|
+
== Views / Templates
|
92
90
|
|
93
|
-
|
91
|
+
Templates are assumed to be located directly under a <tt>./views</tt>
|
92
|
+
directory. To use a different views directory:
|
94
93
|
|
95
|
-
|
96
|
-
your main application.
|
94
|
+
set :views, File.dirname(__FILE__) + '/templates'
|
97
95
|
|
98
96
|
=== Haml Templates
|
99
97
|
|
98
|
+
The haml gem/library is required to render HAML templates:
|
99
|
+
|
100
100
|
get '/' do
|
101
101
|
haml :index
|
102
102
|
end
|
103
103
|
|
104
104
|
Renders <tt>./views/index.haml</tt>.
|
105
105
|
|
106
|
-
=== Erb
|
106
|
+
=== Erb Templates
|
107
107
|
|
108
108
|
get '/' do
|
109
109
|
erb :index
|
@@ -111,11 +111,20 @@ Renders <tt>./views/index.haml</tt>.
|
|
111
111
|
|
112
112
|
Renders <tt>./views/index.erb</tt>
|
113
113
|
|
114
|
-
=== Builder
|
114
|
+
=== Builder Templates
|
115
|
+
|
116
|
+
The builder gem/library is required to render builder templates:
|
117
|
+
|
118
|
+
get '/' do
|
119
|
+
content_type 'application/xml', :charset => 'utf-8'
|
120
|
+
builder :index
|
121
|
+
end
|
122
|
+
|
123
|
+
Renders <tt>./views/index.builder</tt>.
|
115
124
|
|
116
|
-
|
125
|
+
=== Sass Templates
|
117
126
|
|
118
|
-
|
127
|
+
The sass gem/library is required to render Sass templates:
|
119
128
|
|
120
129
|
get '/stylesheet.css' do
|
121
130
|
content_type 'text/css', :charset => 'utf-8'
|
@@ -134,20 +143,19 @@ Renders the inlined template string.
|
|
134
143
|
|
135
144
|
=== Accessing Variables
|
136
145
|
|
137
|
-
Templates are evaluated within the
|
138
|
-
|
139
|
-
blocks can be accessed direcly in views:
|
146
|
+
Templates are evaluated within the same context as the route blocks. Instance
|
147
|
+
variables set in route blocks are available in templates:
|
140
148
|
|
141
149
|
get '/:id' do
|
142
150
|
@foo = Foo.find(params[:id])
|
143
|
-
haml '%h1
|
151
|
+
haml '%h1= @foo.name'
|
144
152
|
end
|
145
153
|
|
146
154
|
Or, specify an explicit Hash of local variables:
|
147
155
|
|
148
156
|
get '/:id' do
|
149
157
|
foo = Foo.find(params[:id])
|
150
|
-
haml '%h1
|
158
|
+
haml '%h1= foo.name', :locals => { :foo => foo }
|
151
159
|
end
|
152
160
|
|
153
161
|
This is typically used when rendering templates as partials from within
|
@@ -157,27 +165,32 @@ other templates.
|
|
157
165
|
|
158
166
|
Templates may be defined at the end of the source file:
|
159
167
|
|
168
|
+
require 'rubygems'
|
169
|
+
require 'sinatra'
|
170
|
+
|
160
171
|
get '/' do
|
161
172
|
haml :index
|
162
173
|
end
|
163
174
|
|
164
|
-
use_in_file_templates!
|
165
|
-
|
166
175
|
__END__
|
167
176
|
|
168
177
|
@@ layout
|
169
|
-
|
170
|
-
|
171
|
-
X
|
178
|
+
%html
|
179
|
+
= yield
|
172
180
|
|
173
181
|
@@ index
|
174
182
|
%div.title Hello world!!!!!
|
175
183
|
|
184
|
+
NOTE: Sinatra will automaticly load any in-file-templates in the
|
185
|
+
source file that first required sinatra. If you have in-file-templates
|
186
|
+
in another source file you will need to explicitly call
|
187
|
+
+use_in_file_templates! on main in that file.
|
188
|
+
|
176
189
|
It's also possible to define named templates using the top-level template
|
177
190
|
method:
|
178
191
|
|
179
192
|
template :layout do
|
180
|
-
"
|
193
|
+
"%html\n =yield\n"
|
181
194
|
end
|
182
195
|
|
183
196
|
template :index do
|
@@ -188,10 +201,17 @@ method:
|
|
188
201
|
haml :index
|
189
202
|
end
|
190
203
|
|
204
|
+
If a template named "layout" exists, it will be used each time a template
|
205
|
+
is rendered. You can disable layouts by passing <tt>:layout => false</tt>.
|
206
|
+
|
207
|
+
get '/' do
|
208
|
+
haml :index, :layout => !request.xhr?
|
209
|
+
end
|
210
|
+
|
191
211
|
== Helpers
|
192
212
|
|
193
|
-
|
194
|
-
|
213
|
+
Use the top-level <tt>helpers</tt> method to define helper methods for use in
|
214
|
+
route blocks and templates:
|
195
215
|
|
196
216
|
helpers do
|
197
217
|
def bar(name)
|
@@ -205,95 +225,89 @@ EventContext instances with the methods defined:
|
|
205
225
|
|
206
226
|
== Filters
|
207
227
|
|
208
|
-
|
228
|
+
Before filters are evaluated before each request within the context of the
|
229
|
+
request and can modify the request and response. Instance variables set in
|
230
|
+
filters are accessible by routes and templates.
|
209
231
|
|
210
232
|
before do
|
211
|
-
|
233
|
+
@note = 'Hi!'
|
234
|
+
request.path_info = '/foo/bar/baz'
|
212
235
|
end
|
213
236
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
throw :halt
|
219
|
-
|
220
|
-
Set the body to the result of a helper method
|
221
|
-
|
222
|
-
throw :halt, :helper_method
|
223
|
-
|
224
|
-
Set the body to the result of a helper method after sending it parameters from
|
225
|
-
the local scope
|
226
|
-
|
227
|
-
throw :halt, [:helper_method, foo, bar]
|
237
|
+
get '/foo/*' do
|
238
|
+
@note #=> 'Hi!'
|
239
|
+
params[:splat] #=> 'bar/baz'
|
240
|
+
end
|
228
241
|
|
229
|
-
|
242
|
+
== Halting
|
230
243
|
|
231
|
-
|
244
|
+
To immediately stop a request during a before filter or route use:
|
232
245
|
|
233
|
-
|
246
|
+
halt
|
234
247
|
|
235
|
-
|
248
|
+
You can also specify a body when halting ...
|
236
249
|
|
237
|
-
|
250
|
+
halt 'this will be the body'
|
238
251
|
|
239
|
-
|
252
|
+
Set the status and body ...
|
240
253
|
|
241
|
-
|
242
|
-
result
|
254
|
+
halt 401, 'go away!'
|
243
255
|
|
244
|
-
|
256
|
+
== Passing
|
245
257
|
|
246
|
-
|
258
|
+
A route can punt processing to the next matching route using the <tt>pass</tt>
|
259
|
+
statement:
|
247
260
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
end
|
261
|
+
get '/guess/:who' do
|
262
|
+
pass unless params[:who] == 'Frank'
|
263
|
+
"You got me!"
|
252
264
|
end
|
253
265
|
|
254
|
-
get '/' do
|
255
|
-
|
266
|
+
get '/guess/*' do
|
267
|
+
"You missed!"
|
256
268
|
end
|
257
269
|
|
258
|
-
|
259
|
-
|
270
|
+
The route block is immediately exited and control continues with the next
|
271
|
+
matching route. If no matching route is found, a 404 is returned.
|
260
272
|
|
261
273
|
== Configuration and Reloading
|
262
274
|
|
263
275
|
Sinatra supports multiple environments and reloading. Reloading happens
|
264
|
-
before
|
265
|
-
your configurations
|
266
|
-
etc.) to protect them from reloading or to
|
276
|
+
before each request when running under the <tt>:development</tt>
|
277
|
+
environment. Wrap your configurations (e.g., database connections, constants,
|
278
|
+
etc.) in <tt>configure</tt> blocks to protect them from reloading or to
|
279
|
+
target specific environments.
|
267
280
|
|
268
|
-
|
281
|
+
Run once, at startup, in any environment:
|
269
282
|
|
270
283
|
configure do
|
271
284
|
...
|
272
285
|
end
|
273
286
|
|
274
|
-
|
287
|
+
Run only when the environment (RACK_ENV environment variable) is set to
|
288
|
+
<tt>:production</tt>.
|
275
289
|
|
276
290
|
configure :production do
|
277
291
|
...
|
278
292
|
end
|
279
293
|
|
280
|
-
|
294
|
+
Run when the environment (RACK_ENV environment variable) is set to
|
295
|
+
either <tt>:production</tt> or <tt>:test</tt>.
|
281
296
|
|
282
297
|
configure :production, :test do
|
283
298
|
...
|
284
299
|
end
|
285
300
|
|
286
|
-
This is also really nifty for error handling.
|
287
|
-
|
288
301
|
== Error handling
|
289
302
|
|
290
|
-
Error handlers run
|
291
|
-
means you get all the goodies it has to offer
|
292
|
-
etc.
|
303
|
+
Error handlers run within the same context as routes and before filters, which
|
304
|
+
means you get all the goodies it has to offer, like <tt>haml</tt>, <tt>erb</tt>,
|
305
|
+
<tt>halt</tt>, etc.
|
293
306
|
|
294
307
|
=== Not Found
|
295
308
|
|
296
|
-
When Sinatra::NotFound is raised, the
|
309
|
+
When a <tt>Sinatra::NotFound</tt> exception is raised, or the response's status
|
310
|
+
code is 404, the <tt>not_found</tt> handler is invoked:
|
297
311
|
|
298
312
|
not_found do
|
299
313
|
'This is nowhere to be found'
|
@@ -301,14 +315,12 @@ When Sinatra::NotFound is raised, the not_found handler is invoked:
|
|
301
315
|
|
302
316
|
=== Error
|
303
317
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
The exception can be obtained from the 'sinatra.error' variable in
|
308
|
-
request.env.
|
318
|
+
The +error+ handler is invoked any time an exception is raised from a route
|
319
|
+
block or before filter. The exception object can be obtained from the
|
320
|
+
'sinatra.error' Rack variable:
|
309
321
|
|
310
322
|
error do
|
311
|
-
'Sorry there was a nasty error - ' +
|
323
|
+
'Sorry there was a nasty error - ' + env['sinatra.error'].name
|
312
324
|
end
|
313
325
|
|
314
326
|
Custom errors:
|
@@ -328,12 +340,12 @@ You get this:
|
|
328
340
|
So what happened was... something bad
|
329
341
|
|
330
342
|
Sinatra installs special not_found and error handlers when running under
|
331
|
-
the development.
|
343
|
+
the development environment.
|
332
344
|
|
333
345
|
== Mime types
|
334
346
|
|
335
|
-
When using send_file or static files you may have mime types Sinatra
|
336
|
-
understand.
|
347
|
+
When using <tt>send_file</tt> or static files you may have mime types Sinatra
|
348
|
+
doesn't understand. Use +mime+ to register them by file extension:
|
337
349
|
|
338
350
|
mime :foo, 'text/foo'
|
339
351
|
|
@@ -374,59 +386,61 @@ typically don't have to +use+ them explicitly.
|
|
374
386
|
|
375
387
|
== Testing
|
376
388
|
|
377
|
-
|
389
|
+
The Sinatra::Test module includes a variety of helper methods for testing
|
390
|
+
your Sinatra app. Sinatra includes support for Test::Unit, test-spec, RSpec,
|
391
|
+
and Bacon through separate source files.
|
392
|
+
|
393
|
+
=== Test::Unit
|
378
394
|
|
379
|
-
require 'rubygems'
|
380
395
|
require 'sinatra'
|
381
396
|
require 'sinatra/test/unit'
|
382
397
|
require 'my_sinatra_app'
|
383
398
|
|
384
399
|
class MyAppTest < Test::Unit::TestCase
|
385
|
-
|
386
400
|
def test_my_default
|
387
|
-
|
401
|
+
get '/'
|
388
402
|
assert_equal 'My Default Page!', @response.body
|
389
403
|
end
|
390
404
|
|
391
405
|
def test_with_agent
|
392
|
-
|
406
|
+
get '/', :agent => 'Songbird'
|
393
407
|
assert_equal 'You're in Songbird!', @response.body
|
394
408
|
end
|
395
409
|
|
396
410
|
...
|
397
|
-
|
398
411
|
end
|
399
412
|
|
400
|
-
=== Test
|
413
|
+
=== Test::Spec
|
414
|
+
|
415
|
+
Install the test-spec gem and require <tt>'sinatra/test/spec'</tt> before
|
416
|
+
your app:
|
401
417
|
|
402
|
-
require 'rubygems'
|
403
418
|
require 'sinatra'
|
404
419
|
require 'sinatra/test/spec'
|
405
420
|
require 'my_sinatra_app'
|
406
421
|
|
407
422
|
describe 'My app' do
|
408
|
-
|
409
423
|
it "should show a default page" do
|
410
|
-
|
424
|
+
get '/'
|
411
425
|
should.be.ok
|
412
426
|
body.should.equal 'My Default Page!'
|
413
427
|
end
|
414
428
|
|
415
429
|
...
|
416
|
-
|
417
430
|
end
|
418
431
|
|
419
432
|
=== RSpec
|
420
433
|
|
421
|
-
|
422
|
-
|
434
|
+
Install the rspec gem and require <tt>'sinatra/test/rspec'</tt> before
|
435
|
+
your app:
|
436
|
+
|
423
437
|
require 'sinatra'
|
424
438
|
require 'sinatra/test/rspec'
|
425
439
|
require 'my_sinatra_app'
|
426
440
|
|
427
441
|
describe 'My app' do
|
428
442
|
it 'should show a default page' do
|
429
|
-
|
443
|
+
get '/'
|
430
444
|
@response.should be_ok
|
431
445
|
@response.body.should == 'My Default Page!'
|
432
446
|
end
|
@@ -435,20 +449,35 @@ typically don't have to +use+ them explicitly.
|
|
435
449
|
|
436
450
|
end
|
437
451
|
|
438
|
-
|
439
|
-
|
452
|
+
=== Bacon
|
453
|
+
|
454
|
+
require 'sinatra'
|
455
|
+
require 'sinatra/test/bacon'
|
456
|
+
require 'my_sinatra_app'
|
457
|
+
|
458
|
+
describe 'My app' do
|
459
|
+
it 'should be ok' do
|
460
|
+
get '/'
|
461
|
+
should.be.ok
|
462
|
+
body.should == 'Im OK'
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
See Sinatra::Test for more information on +get+, +post+, +put+, and
|
467
|
+
friends.
|
440
468
|
|
441
469
|
== Command line
|
442
470
|
|
443
471
|
Sinatra applications can be run directly:
|
444
472
|
|
445
|
-
ruby myapp.rb [-h] [-x] [-p PORT] [-
|
473
|
+
ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-s HANDLER]
|
446
474
|
|
447
475
|
Options are:
|
448
476
|
|
449
477
|
-h # help
|
450
478
|
-p # set the port (default is 4567)
|
451
479
|
-e # set the environment (default is development)
|
480
|
+
-s # specify rack server/handler (default is thin)
|
452
481
|
-x # turn on the mutex lock (default is off)
|
453
482
|
|
454
483
|
== Contributing
|
@@ -481,7 +510,7 @@ screencasts about Git, which you can find here: http://www.gitcasts.com/
|
|
481
510
|
|
482
511
|
at the top of your sinatra_app.rb file:
|
483
512
|
|
484
|
-
|
513
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
|
485
514
|
require 'sinatra'
|
486
515
|
|
487
516
|
get '/about' do
|
data/Rakefile
CHANGED
@@ -8,13 +8,19 @@ task :default => :test
|
|
8
8
|
|
9
9
|
desc 'Run specs with story style output'
|
10
10
|
task :spec do
|
11
|
-
|
11
|
+
pattern = ENV['TEST'] || '.*'
|
12
|
+
sh "specrb --testcase '#{pattern}' --specdox -Ilib:test test/*_test.rb"
|
12
13
|
end
|
13
14
|
|
14
15
|
desc 'Run specs with unit test style output'
|
15
|
-
task :test
|
16
|
-
|
17
|
-
|
16
|
+
task :test do |t|
|
17
|
+
sh "specrb -Ilib:test test/*_test.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Run compatibility specs'
|
21
|
+
task :compat do |t|
|
22
|
+
pattern = ENV['TEST'] || '.*'
|
23
|
+
sh "specrb --testcase '#{pattern}' -Ilib:test compat/*_test.rb"
|
18
24
|
end
|
19
25
|
|
20
26
|
# PACKAGING ============================================================
|
@@ -51,7 +57,12 @@ file package('.gem') => %w[dist/ sinatra.gemspec] + spec.files do |f|
|
|
51
57
|
end
|
52
58
|
|
53
59
|
file package('.tar.gz') => %w[dist/] + spec.files do |f|
|
54
|
-
sh
|
60
|
+
sh <<-SH
|
61
|
+
git archive \
|
62
|
+
--prefix=sinatra-#{source_version}/ \
|
63
|
+
--format=tar \
|
64
|
+
HEAD | gzip > #{f.name}
|
65
|
+
SH
|
55
66
|
end
|
56
67
|
|
57
68
|
# Rubyforge Release / Publish Tasks ==================================
|
@@ -61,6 +72,7 @@ task 'publish:doc' => 'doc/api/index.html' do
|
|
61
72
|
sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/sinatra/'
|
62
73
|
end
|
63
74
|
|
75
|
+
desc 'Publish gem and tarball to rubyforge'
|
64
76
|
task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
|
65
77
|
sh <<-end
|
66
78
|
rubyforge add_release sinatra sinatra #{spec.version} #{package('.gem')} &&
|
@@ -141,11 +153,23 @@ task 'doc:book' => ['book/output/sinatra-book.html']
|
|
141
153
|
|
142
154
|
# Gemspec Helpers ====================================================
|
143
155
|
|
144
|
-
|
156
|
+
def source_version
|
157
|
+
line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
|
158
|
+
line.match(/.*VERSION = '(.*)'/)[1]
|
159
|
+
end
|
160
|
+
|
161
|
+
project_files =
|
162
|
+
FileList[
|
163
|
+
'{lib,test,compat,images}/**',
|
164
|
+
'Rakefile', 'CHANGES', 'README.rdoc'
|
165
|
+
]
|
166
|
+
file 'sinatra.gemspec' => project_files do |f|
|
145
167
|
# read spec file and split out manifest section
|
146
168
|
spec = File.read(f.name)
|
147
|
-
|
148
|
-
|
169
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
170
|
+
# replace version and date
|
171
|
+
head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
|
172
|
+
head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
|
149
173
|
# determine file list from git ls-files
|
150
174
|
files = `git ls-files`.
|
151
175
|
split("\n").
|
@@ -155,8 +179,8 @@ file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
|
|
155
179
|
map{ |file| " #{file}" }.
|
156
180
|
join("\n")
|
157
181
|
# piece file back together and write...
|
158
|
-
|
159
|
-
spec =
|
182
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
183
|
+
spec = [head,manifest,tail].join(" # = MANIFEST =\n")
|
160
184
|
File.open(f.name, 'w') { |io| io.write(spec) }
|
161
185
|
puts "updated #{f.name}"
|
162
186
|
end
|
data/{test → compat}/app_test.rb
RENAMED
@@ -108,7 +108,9 @@ context "Sinatra" do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
specify "renders a body with a redirect" do
|
111
|
-
|
111
|
+
helpers do
|
112
|
+
def foo ; 'blah' ; end
|
113
|
+
end
|
112
114
|
get "/" do
|
113
115
|
redirect 'foo', :foo
|
114
116
|
end
|
@@ -130,13 +132,10 @@ context "Sinatra" do
|
|
130
132
|
end
|
131
133
|
|
132
134
|
specify "stop sets content and ends event" do
|
133
|
-
|
134
|
-
Sinatra::EventContext.any_instance.expects(:foo).never
|
135
|
-
|
136
135
|
get '/set_body' do
|
137
136
|
stop 'Hello!'
|
138
137
|
stop 'World!'
|
139
|
-
|
138
|
+
fail 'stop should have halted'
|
140
139
|
end
|
141
140
|
|
142
141
|
get_it '/set_body'
|
@@ -146,8 +145,13 @@ context "Sinatra" do
|
|
146
145
|
|
147
146
|
end
|
148
147
|
|
149
|
-
|
150
|
-
|
148
|
+
# Deprecated. WTF was going on here? What's the 1 in [:foo, 1] do?
|
149
|
+
xspecify "should set status then call helper with a var" do
|
150
|
+
helpers do
|
151
|
+
def foo
|
152
|
+
'bah!'
|
153
|
+
end
|
154
|
+
end
|
151
155
|
|
152
156
|
get '/set_body' do
|
153
157
|
stop [404, [:foo, 1]]
|
@@ -252,8 +256,6 @@ context "Sinatra" do
|
|
252
256
|
assert_equal 'puted', body
|
253
257
|
end
|
254
258
|
|
255
|
-
# Some Ajax libraries downcase the _method parameter value. Make
|
256
|
-
# sure we can handle that.
|
257
259
|
specify "rewrites POSTs with lowercase _method param to PUT" do
|
258
260
|
put '/' do
|
259
261
|
'puted'
|
@@ -262,7 +264,6 @@ context "Sinatra" do
|
|
262
264
|
body.should.equal 'puted'
|
263
265
|
end
|
264
266
|
|
265
|
-
# Ignore any _method parameters specified in GET requests or on the query string in POST requests.
|
266
267
|
specify "does not rewrite GETs with _method param to PUT" do
|
267
268
|
get '/' do
|
268
269
|
'getted'
|