Syd-sinatra 0.3.2 → 0.9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/AUTHORS +40 -0
  2. data/CHANGES +189 -0
  3. data/README.rdoc +148 -119
  4. data/Rakefile +34 -10
  5. data/{test → compat}/app_test.rb +11 -10
  6. data/{test → compat}/application_test.rb +21 -5
  7. data/compat/builder_test.rb +101 -0
  8. data/compat/erb_test.rb +136 -0
  9. data/{test → compat}/events_test.rb +16 -3
  10. data/compat/filter_test.rb +30 -0
  11. data/compat/haml_test.rb +233 -0
  12. data/compat/helper.rb +30 -0
  13. data/compat/mapped_error_test.rb +72 -0
  14. data/{test → compat}/pipeline_test.rb +9 -4
  15. data/compat/sass_test.rb +57 -0
  16. data/{test → compat}/streaming_test.rb +4 -1
  17. data/lib/sinatra/base.rb +843 -0
  18. data/lib/sinatra/compat.rb +239 -0
  19. data/lib/sinatra/main.rb +48 -0
  20. data/lib/sinatra/test/bacon.rb +17 -0
  21. data/lib/sinatra/test/rspec.rb +7 -8
  22. data/lib/sinatra/test/spec.rb +3 -4
  23. data/lib/sinatra/test/unit.rb +3 -5
  24. data/lib/sinatra/test.rb +114 -0
  25. data/lib/sinatra.rb +6 -1468
  26. data/sinatra.gemspec +68 -35
  27. data/test/base_test.rb +68 -0
  28. data/test/builder_test.rb +50 -87
  29. data/test/data/reload_app_file.rb +3 -0
  30. data/test/erb_test.rb +38 -124
  31. data/test/filter_test.rb +65 -20
  32. data/test/haml_test.rb +51 -216
  33. data/test/helper.rb +23 -5
  34. data/test/helpers_test.rb +361 -0
  35. data/test/mapped_error_test.rb +137 -49
  36. data/test/middleware_test.rb +58 -0
  37. data/test/options_test.rb +97 -0
  38. data/test/reload_test.rb +61 -0
  39. data/test/request_test.rb +18 -0
  40. data/test/result_test.rb +88 -0
  41. data/test/routing_test.rb +391 -0
  42. data/test/sass_test.rb +27 -48
  43. data/test/sinatra_test.rb +13 -0
  44. data/test/static_test.rb +57 -0
  45. data/test/templates_test.rb +88 -0
  46. data/test/views/hello.builder +1 -0
  47. data/test/views/hello.erb +1 -0
  48. data/test/views/hello.haml +1 -0
  49. data/test/views/hello.sass +2 -0
  50. data/test/views/hello.test +1 -0
  51. data/test/views/layout2.builder +3 -0
  52. data/test/views/layout2.erb +2 -0
  53. data/test/views/layout2.haml +2 -0
  54. data/test/views/layout2.test +1 -0
  55. metadata +79 -47
  56. data/ChangeLog +0 -78
  57. data/lib/sinatra/test/methods.rb +0 -76
  58. data/test/event_context_test.rb +0 -15
  59. /data/{test → compat}/custom_error_test.rb +0 -0
  60. /data/{test → compat}/public/foo.xml +0 -0
  61. /data/{test → compat}/sessions_test.rb +0 -0
  62. /data/{test → compat}/sym_params_test.rb +0 -0
  63. /data/{test → compat}/template_test.rb +0 -0
  64. /data/{test → compat}/use_in_file_templates_test.rb +0 -0
  65. /data/{test → compat}/views/foo.builder +0 -0
  66. /data/{test → compat}/views/foo.erb +0 -0
  67. /data/{test → compat}/views/foo.haml +0 -0
  68. /data/{test → compat}/views/foo.sass +0 -0
  69. /data/{test → compat}/views/foo_layout.erb +0 -0
  70. /data/{test → compat}/views/foo_layout.haml +0 -0
  71. /data/{test → compat}/views/layout_test/foo.builder +0 -0
  72. /data/{test → compat}/views/layout_test/foo.erb +0 -0
  73. /data/{test → compat}/views/layout_test/foo.haml +0 -0
  74. /data/{test → compat}/views/layout_test/foo.sass +0 -0
  75. /data/{test → compat}/views/layout_test/layout.builder +0 -0
  76. /data/{test → compat}/views/layout_test/layout.erb +0 -0
  77. /data/{test → compat}/views/layout_test/layout.haml +0 -0
  78. /data/{test → compat}/views/layout_test/layout.sass +0 -0
  79. /data/{test → compat}/views/no_layout/no_layout.builder +0 -0
  80. /data/{test → compat}/views/no_layout/no_layout.haml +0 -0
  81. /data/{images → lib/sinatra/images}/404.png +0 -0
  82. /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
- Simple:
38
+ Basic routes:
49
39
 
50
40
  get '/hi' do
51
41
  ...
52
42
  end
53
43
 
54
- Named parameters:
44
+ Route patterns may include named parameters, accessible via the
45
+ <tt>params</tt> hash:
55
46
 
56
47
  get '/:name' do
57
- # matches /sinatra and the like and sets params[:name]
48
+ # matches "GET /foo" and "GET /bar"
49
+ # params[:name] is 'foo' or 'bar'
50
+ "Hello #{params[:name]}!"
58
51
  end
59
52
 
60
- Splat parameters:
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["splat"] # => ["hello", "world"]
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["splat"] # => ["path/to/file", "xml"]
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
- User agent matching:
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
- # matches non-songbird browsers
79
+ # Matches non-songbird browsers
80
80
  end
81
81
 
82
- == Static files
82
+ == Static Files
83
83
 
84
- Put all of your static content in the ./public directory
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
- root
87
- \ public
87
+ set :public, File.dirname(__FILE__) + '/static'
88
88
 
89
- If a file exists that maps to the REQUEST_PATH then it is served and the
90
- request ends. Otherwise, Sinatra will look for an event that matches the
91
- path.
89
+ == Views / Templates
92
90
 
93
- == Views
91
+ Templates are assumed to be located directly under a <tt>./views</tt>
92
+ directory. To use a different views directory:
94
93
 
95
- Views are searched for in a "views" directory in the same location as
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
- See Sinatra::Builder
125
+ === Sass Templates
117
126
 
118
- === Sass
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 Sinatra::EventContext instance
138
- used to evaluate event blocks. Instance variables set in event
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== @foo.name'
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== foo.name', :locals => { :foo => foo }
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
- X
170
- = yield
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
- "X\n=yield\nX"
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
- The top-level <tt>helpers</tt> method takes a block and extends all
194
- EventContext instances with the methods defined:
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
- These are run in Sinatra::EventContext before every event.
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
- .. this code will run before each event ..
233
+ @note = 'Hi!'
234
+ request.path_info = '/foo/bar/baz'
212
235
  end
213
236
 
214
- == Halt!
215
-
216
- To immediately stop a request during a before filter or event use:
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
- Set the body to a simple string
242
+ == Halting
230
243
 
231
- throw :halt, 'this will be the body'
244
+ To immediately stop a request during a before filter or route use:
232
245
 
233
- Set status then the body
246
+ halt
234
247
 
235
- throw :halt, [401, 'go away!']
248
+ You can also specify a body when halting ...
236
249
 
237
- Set the status then call a helper method with params from local scope
250
+ halt 'this will be the body'
238
251
 
239
- throw :halt, [401, [:helper_method, foo, bar]]
252
+ Set the status and body ...
240
253
 
241
- Run a proc inside the Sinatra::EventContext instance and set the body to the
242
- result
254
+ halt 401, 'go away!'
243
255
 
244
- throw :halt, lambda { puts 'In a proc!'; 'I just wrote to $stdout!' }
256
+ == Passing
245
257
 
246
- Create you own to_result
258
+ A route can punt processing to the next matching route using the <tt>pass</tt>
259
+ statement:
247
260
 
248
- class MyResultObject
249
- def to_result(event_context, *args)
250
- event_context.body = 'This will be the body!
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
- throw :halt, MyResultObject.new
266
+ get '/guess/*' do
267
+ "You missed!"
256
268
  end
257
269
 
258
- Get the gist? If you want more fun with this then checkout <tt>to_result</tt>
259
- on Array, Symbol, Fixnum, NilClass.
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 every request when running under the :development environment. Wrap
265
- your configurations in <tt>configure</tt> (i.e. Database connections, Constants,
266
- etc.) to protect them from reloading or to target specific environments.
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
- All environments:
281
+ Run once, at startup, in any environment:
269
282
 
270
283
  configure do
271
284
  ...
272
285
  end
273
286
 
274
- Production:
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
- Two at a time:
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 inside the current Sinatra::EventContext instance, which
291
- means you get all the goodies it has to offer (i.e. haml, erb, throw :halt,
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 not_found handler is invoked:
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
- By default, the +error+ handler is invoked on Sinatra::ServerError or when
305
- an unknown error occurs.
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 - ' + request.env['sinatra.error'].name
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 doesn't
336
- understand. Use +mime+ in those cases.
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
- === Test/Unit
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
- get_it '/'
401
+ get '/'
388
402
  assert_equal 'My Default Page!', @response.body
389
403
  end
390
404
 
391
405
  def test_with_agent
392
- get_it '/', :agent => 'Songbird'
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/Spec
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
- get_it '/'
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
- require 'rubygems'
422
- require 'spec'
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
- get_it '/'
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
- See Sinatra::Test::Methods for more information on +get_it+, +post_it+,
439
- +put_it+, and friends.
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] [-e ENVIRONMENT]
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
- $:.unshift File.dirname(__FILE__) + '/sinatra/lib'
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
- sh 'specrb --specdox -Ilib:test test/*_test.rb'
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 => FileList['test/*_test.rb'] do |t|
16
- suite = t.prerequisites.map{|f| "-r#{f.chomp('.rb')}"}.join(' ')
17
- sh "ruby -Ilib:test #{suite} -e ''", :verbose => false
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 "git archive --format=tar HEAD | gzip > #{f.name}"
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
- file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
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
- parts = spec.split(" # = MANIFEST =\n")
148
- fail 'bad spec' if parts.length != 3
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
- parts[1] = " s.files = %w[\n#{files}\n ]\n"
159
- spec = parts.join(" # = MANIFEST =\n")
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
@@ -108,7 +108,9 @@ context "Sinatra" do
108
108
  end
109
109
 
110
110
  specify "renders a body with a redirect" do
111
- Sinatra::EventContext.any_instance.expects(:foo).returns('blah')
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
- foo
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
- specify "should set status then call helper with a var" do
150
- Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!')
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'