sinatra 0.9.0.5 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/AUTHORS +8 -7
- data/CHANGES +70 -0
- data/README.rdoc +86 -155
- data/Rakefile +9 -59
- data/compat/app_test.rb +3 -21
- data/compat/application_test.rb +0 -72
- data/compat/pipeline_test.rb +0 -26
- data/compat/sessions_test.rb +3 -0
- data/compat/streaming_test.rb +15 -3
- data/lib/sinatra/base.rb +290 -142
- data/lib/sinatra/compat.rb +30 -30
- data/lib/sinatra/main.rb +4 -5
- data/lib/sinatra/test/bacon.rb +2 -0
- data/lib/sinatra/test/rspec.rb +2 -0
- data/lib/sinatra/test/spec.rb +2 -0
- data/lib/sinatra/test/unit.rb +2 -0
- data/lib/sinatra/test.rb +62 -50
- data/sinatra.gemspec +7 -3
- data/test/base_test.rb +108 -46
- data/test/erb_test.rb +31 -0
- data/test/extensions_test.rb +84 -0
- data/test/helper.rb +65 -9
- data/test/helpers_test.rb +469 -333
- data/test/mapped_error_test.rb +6 -6
- data/test/middleware_test.rb +13 -3
- data/test/options_test.rb +278 -1
- data/test/reload_test.rb +7 -0
- data/test/response_test.rb +42 -0
- data/test/result_test.rb +10 -0
- data/test/routing_test.rb +269 -2
- data/test/server_test.rb +41 -0
- data/test/static_test.rb +8 -25
- data/test/test_test.rb +144 -0
- metadata +13 -2
data/AUTHORS
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Sinatra was designed and developed by Blake Mizerany (bmizerany) in
|
2
2
|
California. Continued development would not be possible without the ongoing
|
3
|
-
financial support provided by Heroku
|
4
|
-
provided by Adam Wiggins (adamwiggins), Chris Wanstrath (defunkt),
|
5
|
-
the rest of the
|
3
|
+
financial support provided by [Heroku](http://heroku.com) and the emotional
|
4
|
+
support provided by Adam Wiggins (adamwiggins) of Heroku, Chris Wanstrath (defunkt),
|
5
|
+
PJ Hyett (pjhyett), and the rest of the GitHub crew.
|
6
6
|
|
7
7
|
Special thanks to the following extraordinary individuals, who-out which
|
8
8
|
Sinatra would not be possible:
|
9
9
|
|
10
|
-
* Ryan Tomayko (rtomayko) for constantly fixing whitespace errors 60d5006
|
10
|
+
* Ryan Tomayko (rtomayko) for constantly fixing whitespace errors 60d5006
|
11
11
|
* Ezra Zygmuntowicz (ezmobius) for initial help and letting Blake steal
|
12
12
|
some of merbs internal code.
|
13
13
|
* Christopher Schneid (cschneid) for The Book, the blog (gittr.com),
|
@@ -16,7 +16,7 @@ Sinatra would not be possible:
|
|
16
16
|
the README, and hanging in there when times were rough.
|
17
17
|
* Simon Rozet (sr) for a ton of doc patches, HAML options, and all that
|
18
18
|
advocacy stuff he's going to do for 1.0.
|
19
|
-
* Erik Kastner (kastner) for fixing MIME_TYPES under Rack 0.5.
|
19
|
+
* Erik Kastner (kastner) for fixing `MIME_TYPES` under Rack 0.5.
|
20
20
|
* Ben Bleything (bleything) for caring about HTTP status codes and doc fixes.
|
21
21
|
* Igal Koshevoy (igal) for root path detection under Thin/Passenger.
|
22
22
|
* Jon Crosby (jcrosby) for coffee breaks, doc fixes, and just because, man.
|
@@ -27,12 +27,13 @@ Sinatra would not be possible:
|
|
27
27
|
* Victor Hugo Borja (vic) for splat'n routes specs and doco.
|
28
28
|
* Avdi Grimm (avdi) for basic RSpec support.
|
29
29
|
* Jack Danger Canty for a more accurate root directory and for making me
|
30
|
-
watch this
|
30
|
+
watch [this](http://www.youtube.com/watch?v=ueaHLHgskkw) just now.
|
31
31
|
* Mathew Walker for making escaped paths work with static files.
|
32
32
|
* Millions of Us for having the problem that led to Sinatra's conception.
|
33
33
|
* Songbird for the problems that helped Sinatra's future become realized.
|
34
|
-
* Rick
|
34
|
+
* Rick Olson (technoweenie) for the killer plug at RailsConf '08.
|
35
35
|
* Steven Garcia for the amazing custom artwork you see on 404's and 500's
|
36
|
+
* Pat Nakajima (nakajima) for fixing non-nested params in nested params Hash's.
|
36
37
|
|
37
38
|
and last but not least:
|
38
39
|
|
data/CHANGES
CHANGED
@@ -1,3 +1,73 @@
|
|
1
|
+
= 0.9.1 / 2009-03-01
|
2
|
+
|
3
|
+
* Sinatra now runs under Ruby 1.9.1 [#61]
|
4
|
+
|
5
|
+
* Route patterns (splats, :named, or Regexp captures) are now
|
6
|
+
passed as arguments to the block. [#140]
|
7
|
+
|
8
|
+
* The "helpers" method now takes a variable number of modules
|
9
|
+
along with the normal block syntax. [#133]
|
10
|
+
|
11
|
+
* New request-level #forward method for middleware components: passes
|
12
|
+
the env to the downstream app and merges the response status, headers,
|
13
|
+
and body into the current context. [#126]
|
14
|
+
|
15
|
+
* Requests are now automatically forwarded to the downstream app when
|
16
|
+
running as middleware and no matching route is found or all routes
|
17
|
+
pass.
|
18
|
+
|
19
|
+
* New simple API for extensions/plugins to add DSL-level and
|
20
|
+
request-level methods. Use Sinatra.register(mixin) to extend
|
21
|
+
the DSL with all public methods defined in the mixin module;
|
22
|
+
use Sinatra.helpers(mixin) to make all public methods defined
|
23
|
+
in the mixin module available at the request level. [#138]
|
24
|
+
See http://www.sinatrarb.com/extensions.html for details.
|
25
|
+
|
26
|
+
* Named parameters in routes now capture the "." character. This makes
|
27
|
+
routes like "/:path/:filename" match against requests like
|
28
|
+
"/foo/bar.txt"; in this case, "params[:filename]" is "bar.txt".
|
29
|
+
Previously, the route would not match at all.
|
30
|
+
|
31
|
+
* Added request-level "redirect back" to redirect to the referring
|
32
|
+
URL.
|
33
|
+
|
34
|
+
* Added a new "clean_trace" option that causes backtraces dumped
|
35
|
+
to rack.errors and displayed on the development error page to
|
36
|
+
omit framework and core library backtrace lines. The option is
|
37
|
+
enabled by default. [#77]
|
38
|
+
|
39
|
+
* The ERB output buffer is now available to helpers via the @_out_buf
|
40
|
+
instance variable.
|
41
|
+
|
42
|
+
* It's now much easier to test sessions in unit tests by passing a
|
43
|
+
":session" option to any of the mock request methods. e.g.,
|
44
|
+
get '/', {}, :session => { 'foo' => 'bar' }
|
45
|
+
|
46
|
+
* The testing framework specific files ('sinatra/test/spec',
|
47
|
+
'sinatra/test/bacon', 'sinatra/test/rspec', etc.) have been deprecated.
|
48
|
+
See http://sinatrarb.com/testing.html for instructions on setting up
|
49
|
+
a testing environment with these frameworks.
|
50
|
+
|
51
|
+
* The request-level #send_data method from Sinatra 0.3.3 has been added
|
52
|
+
for compatibility but is deprecated.
|
53
|
+
|
54
|
+
* Fix :provides causing crash on any request when request has no
|
55
|
+
Accept header [#139]
|
56
|
+
|
57
|
+
* Fix that ERB templates were evaluated twice per "erb" call.
|
58
|
+
|
59
|
+
* Fix app-level middleware not being run when the Sinatra application is
|
60
|
+
run as middleware.
|
61
|
+
|
62
|
+
* Fixed some issues with running under Rack's CGI handler caused by
|
63
|
+
writing informational stuff to stdout.
|
64
|
+
|
65
|
+
* Fixed that reloading was sometimes enabled when starting from a
|
66
|
+
rackup file [#110]
|
67
|
+
|
68
|
+
* Fixed that "." in route patterns erroneously matched any character
|
69
|
+
instead of a literal ".". [#124]
|
70
|
+
|
1
71
|
= 0.9.0.4 / 2009-01-25
|
2
72
|
|
3
73
|
* Using halt with more than 1 args causes ArgumentError [#131]
|
data/README.rdoc
CHANGED
@@ -10,12 +10,20 @@ effort:
|
|
10
10
|
'Hello world!'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
Install the gem and run with:
|
14
14
|
|
15
|
-
|
15
|
+
sudo gem install sinatra
|
16
|
+
ruby myapp.rb
|
17
|
+
|
18
|
+
View at: http://localhost:4567
|
19
|
+
|
20
|
+
== Routes
|
21
|
+
|
22
|
+
In Sinatra, a route is an HTTP method paired with an URL matching pattern.
|
23
|
+
Each route is associated with a block:
|
16
24
|
|
17
25
|
get '/' do
|
18
|
-
.. show
|
26
|
+
.. show something ..
|
19
27
|
end
|
20
28
|
|
21
29
|
post '/' do
|
@@ -30,26 +38,24 @@ Run with <tt>ruby myapp.rb</tt> and view at <tt>http://localhost:4567</tt>
|
|
30
38
|
.. annihilate something ..
|
31
39
|
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
Routes are matched based on the order of declaration. The first route that
|
41
|
+
Routes are matched in the order they are defined. The first route that
|
36
42
|
matches the request is invoked.
|
37
43
|
|
38
|
-
Basic routes:
|
39
|
-
|
40
|
-
get '/hi' do
|
41
|
-
...
|
42
|
-
end
|
43
|
-
|
44
44
|
Route patterns may include named parameters, accessible via the
|
45
45
|
<tt>params</tt> hash:
|
46
46
|
|
47
|
-
get '/:name' do
|
47
|
+
get '/hello/:name' do
|
48
48
|
# matches "GET /foo" and "GET /bar"
|
49
49
|
# params[:name] is 'foo' or 'bar'
|
50
50
|
"Hello #{params[:name]}!"
|
51
51
|
end
|
52
52
|
|
53
|
+
You can also access named parameters via block parameters:
|
54
|
+
|
55
|
+
get '/hello/:name' do |n|
|
56
|
+
"Hello #{n}!"
|
57
|
+
end
|
58
|
+
|
53
59
|
Route patterns may also include splat (or wildcard) parameters, accessible
|
54
60
|
via the <tt>params[:splat]</tt> array.
|
55
61
|
|
@@ -69,6 +75,12 @@ Route matching with Regular Expressions:
|
|
69
75
|
"Hello, #{params[:captures].first}!"
|
70
76
|
end
|
71
77
|
|
78
|
+
Or with a block parameter:
|
79
|
+
|
80
|
+
get %r{/hello/([\w]+)} do |c|
|
81
|
+
"Hello, #{c}!"
|
82
|
+
end
|
83
|
+
|
72
84
|
Routes may include a variety of matching conditions, such as the user agent:
|
73
85
|
|
74
86
|
get '/foo', :agent => /Songbird (\d\.\d)[\d\/]*?/ do
|
@@ -86,9 +98,13 @@ a different location by setting the <tt>:public</tt> option:
|
|
86
98
|
|
87
99
|
set :public, File.dirname(__FILE__) + '/static'
|
88
100
|
|
101
|
+
Note that the public directory name is not included in the URL. A file
|
102
|
+
<tt>./public/css/style.css</tt> is made available as
|
103
|
+
<tt>http://example.com/css/style.css</tt>.
|
104
|
+
|
89
105
|
== Views / Templates
|
90
106
|
|
91
|
-
Templates are assumed to be located directly under
|
107
|
+
Templates are assumed to be located directly under the <tt>./views</tt>
|
92
108
|
directory. To use a different views directory:
|
93
109
|
|
94
110
|
set :views, File.dirname(__FILE__) + '/templates'
|
@@ -141,10 +157,10 @@ Renders <tt>./views/stylesheet.sass</tt>.
|
|
141
157
|
|
142
158
|
Renders the inlined template string.
|
143
159
|
|
144
|
-
=== Accessing Variables
|
160
|
+
=== Accessing Variables in Templates
|
145
161
|
|
146
|
-
Templates are evaluated within the same context as
|
147
|
-
variables set in route
|
162
|
+
Templates are evaluated within the same context as route handlers. Instance
|
163
|
+
variables set in route handlers are direcly accessible by templates:
|
148
164
|
|
149
165
|
get '/:id' do
|
150
166
|
@foo = Foo.find(params[:id])
|
@@ -181,13 +197,13 @@ Templates may be defined at the end of the source file:
|
|
181
197
|
@@ index
|
182
198
|
%div.title Hello world!!!!!
|
183
199
|
|
184
|
-
NOTE:
|
185
|
-
|
186
|
-
|
187
|
-
+use_in_file_templates! on main in that file.
|
200
|
+
NOTE: In-file templates defined in the source file that requires sinatra
|
201
|
+
are automatically loaded. Call the <tt>use_in_file_templates!</tt>
|
202
|
+
method explicitly if you have in-file templates in other source files.
|
188
203
|
|
189
|
-
|
190
|
-
|
204
|
+
=== Named Templates
|
205
|
+
|
206
|
+
Templates may also be defined using the top-level <tt>template</tt> method:
|
191
207
|
|
192
208
|
template :layout do
|
193
209
|
"%html\n =yield\n"
|
@@ -211,7 +227,7 @@ is rendered. You can disable layouts by passing <tt>:layout => false</tt>.
|
|
211
227
|
== Helpers
|
212
228
|
|
213
229
|
Use the top-level <tt>helpers</tt> method to define helper methods for use in
|
214
|
-
route
|
230
|
+
route handlers and templates:
|
215
231
|
|
216
232
|
helpers do
|
217
233
|
def bar(name)
|
@@ -227,7 +243,7 @@ route blocks and templates:
|
|
227
243
|
|
228
244
|
Before filters are evaluated before each request within the context of the
|
229
245
|
request and can modify the request and response. Instance variables set in
|
230
|
-
filters are accessible by routes and templates
|
246
|
+
filters are accessible by routes and templates:
|
231
247
|
|
232
248
|
before do
|
233
249
|
@note = 'Hi!'
|
@@ -249,14 +265,13 @@ You can also specify a body when halting ...
|
|
249
265
|
|
250
266
|
halt 'this will be the body'
|
251
267
|
|
252
|
-
|
268
|
+
Or set the status and body ...
|
253
269
|
|
254
270
|
halt 401, 'go away!'
|
255
271
|
|
256
272
|
== Passing
|
257
273
|
|
258
|
-
A route can punt processing to the next matching route using
|
259
|
-
statement:
|
274
|
+
A route can punt processing to the next matching route using <tt>pass</tt>:
|
260
275
|
|
261
276
|
get '/guess/:who' do
|
262
277
|
pass unless params[:who] == 'Frank'
|
@@ -317,7 +332,7 @@ code is 404, the <tt>not_found</tt> handler is invoked:
|
|
317
332
|
|
318
333
|
The +error+ handler is invoked any time an exception is raised from a route
|
319
334
|
block or before filter. The exception object can be obtained from the
|
320
|
-
|
335
|
+
<tt>sinatra.error</tt> Rack variable:
|
321
336
|
|
322
337
|
error do
|
323
338
|
'Sorry there was a nasty error - ' + env['sinatra.error'].name
|
@@ -339,8 +354,8 @@ You get this:
|
|
339
354
|
|
340
355
|
So what happened was... something bad
|
341
356
|
|
342
|
-
Sinatra installs special not_found and error handlers when
|
343
|
-
the development environment.
|
357
|
+
Sinatra installs special <tt>not_found</tt> and <tt>error</tt> handlers when
|
358
|
+
running under the development environment.
|
344
359
|
|
345
360
|
== Mime types
|
346
361
|
|
@@ -386,85 +401,34 @@ typically don't have to +use+ them explicitly.
|
|
386
401
|
|
387
402
|
== Testing
|
388
403
|
|
389
|
-
The Sinatra::Test
|
390
|
-
|
391
|
-
and Bacon through separate source files.
|
392
|
-
|
393
|
-
=== Test::Unit
|
404
|
+
The Sinatra::Test mixin and Sinatra::TestHarness class include a variety of
|
405
|
+
helper methods for testing your Sinatra app:
|
394
406
|
|
395
|
-
require 'sinatra'
|
396
|
-
require 'sinatra/test/unit'
|
397
407
|
require 'my_sinatra_app'
|
408
|
+
require 'test/unit'
|
409
|
+
require 'sinatra/test'
|
398
410
|
|
399
411
|
class MyAppTest < Test::Unit::TestCase
|
412
|
+
include Sinatra::Test
|
413
|
+
|
400
414
|
def test_my_default
|
401
415
|
get '/'
|
402
|
-
assert_equal '
|
416
|
+
assert_equal 'Hello World!', @response.body
|
403
417
|
end
|
404
418
|
|
405
|
-
def
|
406
|
-
get '/', :
|
407
|
-
assert_equal '
|
419
|
+
def test_with_params
|
420
|
+
get '/meet', {:name => 'Frank'}
|
421
|
+
assert_equal 'Hello Frank!', @response.body
|
408
422
|
end
|
409
423
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
=== Test::Spec
|
414
|
-
|
415
|
-
Install the test-spec gem and require <tt>'sinatra/test/spec'</tt> before
|
416
|
-
your app:
|
417
|
-
|
418
|
-
require 'sinatra'
|
419
|
-
require 'sinatra/test/spec'
|
420
|
-
require 'my_sinatra_app'
|
421
|
-
|
422
|
-
describe 'My app' do
|
423
|
-
it "should show a default page" do
|
424
|
-
get '/'
|
425
|
-
should.be.ok
|
426
|
-
body.should.equal 'My Default Page!'
|
424
|
+
def test_with_rack_env
|
425
|
+
get '/', {}, :agent => 'Songbird'
|
426
|
+
assert_equal "You're using Songbird!", @response.body
|
427
427
|
end
|
428
|
-
|
429
|
-
...
|
430
428
|
end
|
431
429
|
|
432
|
-
|
433
|
-
|
434
|
-
Install the rspec gem and require <tt>'sinatra/test/rspec'</tt> before
|
435
|
-
your app:
|
436
|
-
|
437
|
-
require 'sinatra'
|
438
|
-
require 'sinatra/test/rspec'
|
439
|
-
require 'my_sinatra_app'
|
440
|
-
|
441
|
-
describe 'My app' do
|
442
|
-
it 'should show a default page' do
|
443
|
-
get '/'
|
444
|
-
@response.should be_ok
|
445
|
-
@response.body.should == 'My Default Page!'
|
446
|
-
end
|
447
|
-
|
448
|
-
...
|
449
|
-
|
450
|
-
end
|
451
|
-
|
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.
|
430
|
+
See http://www.sinatrarb.com/testing.html for more on Sinatra::Test and using it
|
431
|
+
with other test frameworks such as RSpec, Bacon, and test/spec.
|
468
432
|
|
469
433
|
== Command line
|
470
434
|
|
@@ -480,73 +444,40 @@ Options are:
|
|
480
444
|
-s # specify rack server/handler (default is thin)
|
481
445
|
-x # turn on the mutex lock (default is off)
|
482
446
|
|
483
|
-
==
|
484
|
-
|
485
|
-
=== Tools
|
447
|
+
== The Bleeding Edge
|
486
448
|
|
487
|
-
|
488
|
-
|
489
|
-
|
449
|
+
If you would like to use Sinatra's latest bleeding code, create a local
|
450
|
+
clone and run your app with the <tt>sinatra/lib</tt> directory on the
|
451
|
+
<tt>LOAD_PATH</tt>:
|
490
452
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
screencasts about Git, which you can find here: http://www.gitcasts.com/
|
453
|
+
cd myapp
|
454
|
+
git clone git://github.com/sinatra/sinatra.git
|
455
|
+
ruby -Isinatra/lib myapp.rb
|
495
456
|
|
496
|
-
|
497
|
-
|
498
|
-
cd where/you/keep/your/projects
|
499
|
-
git clone git://github.com/bmizerany/sinatra.git
|
500
|
-
cd sinatra
|
501
|
-
cd path/to/your_project
|
502
|
-
ln -s ../sinatra/
|
503
|
-
|
504
|
-
=== Updating Your Existing Sinatra Clone
|
505
|
-
|
506
|
-
cd where/you/keep/sinatra
|
507
|
-
git pull
|
508
|
-
|
509
|
-
=== Using Edge Sinatra in Your App
|
510
|
-
|
511
|
-
at the top of your sinatra_app.rb file:
|
457
|
+
Alternatively, you can add the <tt>sinatra/lib<tt> directory to the
|
458
|
+
<tt>LOAD_PATH</tt> in your application:
|
512
459
|
|
513
460
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
|
461
|
+
require 'rubygems'
|
514
462
|
require 'sinatra'
|
515
463
|
|
516
464
|
get '/about' do
|
517
|
-
"I'm running
|
465
|
+
"I'm running version " + Sinatra::VERSION
|
518
466
|
end
|
519
467
|
|
520
|
-
|
521
|
-
|
522
|
-
There are several ways to do this. Probably the easiest (and preferred) way is
|
523
|
-
to fork Sinatra on GitHub (http://github.com/bmizerany/sinatra), push your
|
524
|
-
changes to your Sinatra repo, and then send Blake Mizerany (bmizerany on
|
525
|
-
GitHub) a pull request.
|
526
|
-
|
527
|
-
You can also create a patch file and attach it to a feature request or bug fix
|
528
|
-
on the issue tracker (see below) or send it to the mailing list (see Community
|
529
|
-
section).
|
468
|
+
To update the Sinatra sources in the future:
|
530
469
|
|
531
|
-
|
532
|
-
|
533
|
-
http://sinatra.lighthouseapp.com/
|
534
|
-
|
535
|
-
== Community
|
536
|
-
|
537
|
-
=== Mailing List
|
538
|
-
|
539
|
-
http://groups.google.com/group/sinatrarb
|
540
|
-
|
541
|
-
If you have a problem or question, please make sure to include all the
|
542
|
-
relevant information in your mail, like the Sinatra version you're using, what
|
543
|
-
version of Ruby you have, and so on.
|
544
|
-
|
545
|
-
=== IRC Channel
|
546
|
-
|
547
|
-
You can find us on the Freenode network in the channel #sinatra
|
548
|
-
(irc://chat.freenode.net/#sinatra)
|
470
|
+
cd myproject/sinatra
|
471
|
+
git pull
|
549
472
|
|
550
|
-
|
551
|
-
|
552
|
-
|
473
|
+
== More
|
474
|
+
|
475
|
+
* {Project Website}[http://sinatra.github.com/] - Additional documentation,
|
476
|
+
news, and links to other resources.
|
477
|
+
* {Contributing}[http://sinatra.github.com/contributing.html] - Find a bug? Need
|
478
|
+
help? Have a patch?
|
479
|
+
* {Lighthouse}[http://sinatra.lighthouseapp.com] - Issue tracking and release
|
480
|
+
planning.
|
481
|
+
* {Twitter}[http://twitter.com/sinatra]
|
482
|
+
* {Mailing List}[http://groups.google.com/group/sinatrarb]
|
483
|
+
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
|
data/Rakefile
CHANGED
@@ -1,23 +1,18 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake/clean'
|
2
|
+
require 'rake/testtask'
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
|
-
task :default => :test
|
5
|
+
task :default => [:test]
|
6
|
+
task :spec => :test
|
6
7
|
|
7
8
|
# SPECS ===============================================================
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
sh "specrb --testcase '#{pattern}' --specdox -Ilib:test test/*_test.rb"
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Run specs with unit test style output'
|
16
|
-
task :test do |t|
|
17
|
-
sh "specrb -Ilib:test test/*_test.rb"
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.test_files = FileList['test/*_test.rb']
|
12
|
+
t.ruby_opts = ['-rubygems'] if defined? Gem
|
18
13
|
end
|
19
14
|
|
20
|
-
desc 'Run compatibility specs'
|
15
|
+
desc 'Run compatibility specs (requires test/spec)'
|
21
16
|
task :compat do |t|
|
22
17
|
pattern = ENV['TEST'] || '.*'
|
23
18
|
sh "specrb --testcase '#{pattern}' -Ilib:test compat/*_test.rb"
|
@@ -50,6 +45,7 @@ task :install => package('.gem') do
|
|
50
45
|
end
|
51
46
|
|
52
47
|
directory 'dist/'
|
48
|
+
CLOBBER.include('dist')
|
53
49
|
|
54
50
|
file package('.gem') => %w[dist/ sinatra.gemspec] + spec.files do |f|
|
55
51
|
sh "gem build sinatra.gemspec"
|
@@ -67,11 +63,6 @@ end
|
|
67
63
|
|
68
64
|
# Rubyforge Release / Publish Tasks ==================================
|
69
65
|
|
70
|
-
desc 'Publish website to rubyforge'
|
71
|
-
task 'publish:doc' => 'doc/api/index.html' do
|
72
|
-
sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/sinatra/'
|
73
|
-
end
|
74
|
-
|
75
66
|
desc 'Publish gem and tarball to rubyforge'
|
76
67
|
task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
|
77
68
|
sh <<-end
|
@@ -84,7 +75,7 @@ end
|
|
84
75
|
# Building docs requires HAML and the hanna gem:
|
85
76
|
# gem install mislav-hanna --source=http://gems.github.com
|
86
77
|
|
87
|
-
task 'doc' => ['doc:api'
|
78
|
+
task 'doc' => ['doc:api']
|
88
79
|
|
89
80
|
desc 'Generate Hanna RDoc under doc/api'
|
90
81
|
task 'doc:api' => ['doc/api/index.html']
|
@@ -110,47 +101,6 @@ def rdoc_to_html(file_name)
|
|
110
101
|
rdoc.convert(File.read(file_name))
|
111
102
|
end
|
112
103
|
|
113
|
-
def haml(locals={})
|
114
|
-
require 'haml'
|
115
|
-
template = File.read('doc/template.haml')
|
116
|
-
haml = Haml::Engine.new(template, :format => :html4, :attr_wrapper => '"')
|
117
|
-
haml.render(Object.new, locals)
|
118
|
-
end
|
119
|
-
|
120
|
-
desc 'Build website HTML and stuff'
|
121
|
-
task 'doc:site' => ['doc/index.html', 'doc/book.html']
|
122
|
-
|
123
|
-
file 'doc/index.html' => %w[README.rdoc doc/template.haml] do |file|
|
124
|
-
File.open(file.name, 'w') do |file|
|
125
|
-
file << haml(:title => 'Sinatra', :content => rdoc_to_html('README.rdoc'))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
CLEAN.include 'doc/index.html'
|
129
|
-
|
130
|
-
file 'doc/book.html' => ['book/output/sinatra-book.html'] do |file|
|
131
|
-
File.open(file.name, 'w') do |file|
|
132
|
-
book_content = File.read('book/output/sinatra-book.html')
|
133
|
-
file << haml(:title => 'Sinatra Book', :content => book_content)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
CLEAN.include 'doc/book.html'
|
137
|
-
|
138
|
-
file 'book/output/sinatra-book.html' => FileList['book/**'] do |f|
|
139
|
-
unless File.directory?('book')
|
140
|
-
sh 'git clone git://github.com/cschneid/sinatra-book.git book'
|
141
|
-
end
|
142
|
-
sh((<<-SH).strip.gsub(/\s+/, ' '))
|
143
|
-
cd book &&
|
144
|
-
git fetch origin &&
|
145
|
-
git rebase origin/master &&
|
146
|
-
thor book:build
|
147
|
-
SH
|
148
|
-
end
|
149
|
-
CLEAN.include 'book/output/sinatra-book.html'
|
150
|
-
|
151
|
-
desc 'Build the Sinatra book'
|
152
|
-
task 'doc:book' => ['book/output/sinatra-book.html']
|
153
|
-
|
154
104
|
# Gemspec Helpers ====================================================
|
155
105
|
|
156
106
|
def source_version
|
data/compat/app_test.rb
CHANGED
@@ -8,8 +8,9 @@ context "Sinatra" do
|
|
8
8
|
|
9
9
|
specify "should put all DSL methods on (main)" do
|
10
10
|
object = Object.new
|
11
|
-
|
12
|
-
|
11
|
+
methods = %w[get put post head delete configure template helpers set]
|
12
|
+
methods.each do |method|
|
13
|
+
object.private_methods.map { |m| m.to_sym }.should.include(method.to_sym)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -145,25 +146,6 @@ context "Sinatra" do
|
|
145
146
|
|
146
147
|
end
|
147
148
|
|
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
|
155
|
-
|
156
|
-
get '/set_body' do
|
157
|
-
stop [404, [:foo, 1]]
|
158
|
-
end
|
159
|
-
|
160
|
-
get_it '/set_body'
|
161
|
-
|
162
|
-
should.be.not_found
|
163
|
-
body.should.equal 'bah!'
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
149
|
specify "should easily set response Content-Type" do
|
168
150
|
get '/foo.html' do
|
169
151
|
content_type 'text/html', :charset => 'utf-8'
|