sinatra 0.2.2 → 0.3.0

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.

Files changed (109) hide show
  1. data/ChangeLog +64 -0
  2. data/LICENSE +1 -1
  3. data/README.rdoc +244 -141
  4. data/Rakefile +111 -0
  5. data/lib/sinatra.rb +942 -627
  6. data/{vendor/rack/lib → lib/sinatra}/rack/handler/mongrel.rb +10 -3
  7. data/lib/sinatra/test/methods.rb +56 -36
  8. data/lib/sinatra/test/rspec.rb +10 -0
  9. data/lib/sinatra/test/spec.rb +2 -2
  10. data/lib/sinatra/test/unit.rb +1 -1
  11. data/sinatra.gemspec +71 -43
  12. data/test/app_test.rb +181 -32
  13. data/test/application_test.rb +179 -36
  14. data/test/custom_error_test.rb +17 -22
  15. data/test/erb_test.rb +42 -22
  16. data/test/event_context_test.rb +3 -3
  17. data/test/events_test.rb +8 -11
  18. data/test/filter_test.rb +30 -0
  19. data/test/haml_test.rb +83 -31
  20. data/test/helper.rb +6 -3
  21. data/test/mapped_error_test.rb +32 -21
  22. data/test/pipeline_test.rb +66 -0
  23. data/test/sass_test.rb +7 -7
  24. data/test/sessions_test.rb +8 -9
  25. data/test/streaming_test.rb +10 -4
  26. data/test/sym_params_test.rb +1 -1
  27. data/test/template_test.rb +11 -11
  28. data/test/use_in_file_templates_test.rb +9 -10
  29. metadata +22 -101
  30. data/CHANGELOG +0 -3
  31. data/Manifest +0 -122
  32. data/index.html +0 -9
  33. data/test/diddy_test.rb +0 -41
  34. data/test/rest_test.rb +0 -16
  35. data/vendor/rack/AUTHORS +0 -7
  36. data/vendor/rack/COPYING +0 -18
  37. data/vendor/rack/KNOWN-ISSUES +0 -18
  38. data/vendor/rack/README +0 -242
  39. data/vendor/rack/Rakefile +0 -174
  40. data/vendor/rack/bin/rackup +0 -153
  41. data/vendor/rack/contrib/rack_logo.svg +0 -111
  42. data/vendor/rack/example/lobster.ru +0 -4
  43. data/vendor/rack/example/protectedlobster.rb +0 -14
  44. data/vendor/rack/example/protectedlobster.ru +0 -8
  45. data/vendor/rack/lib/rack.rb +0 -92
  46. data/vendor/rack/lib/rack/adapter/camping.rb +0 -22
  47. data/vendor/rack/lib/rack/auth/abstract/handler.rb +0 -28
  48. data/vendor/rack/lib/rack/auth/abstract/request.rb +0 -37
  49. data/vendor/rack/lib/rack/auth/basic.rb +0 -58
  50. data/vendor/rack/lib/rack/auth/digest/md5.rb +0 -124
  51. data/vendor/rack/lib/rack/auth/digest/nonce.rb +0 -51
  52. data/vendor/rack/lib/rack/auth/digest/params.rb +0 -55
  53. data/vendor/rack/lib/rack/auth/digest/request.rb +0 -40
  54. data/vendor/rack/lib/rack/auth/openid.rb +0 -116
  55. data/vendor/rack/lib/rack/builder.rb +0 -56
  56. data/vendor/rack/lib/rack/cascade.rb +0 -36
  57. data/vendor/rack/lib/rack/commonlogger.rb +0 -56
  58. data/vendor/rack/lib/rack/file.rb +0 -112
  59. data/vendor/rack/lib/rack/handler/cgi.rb +0 -57
  60. data/vendor/rack/lib/rack/handler/fastcgi.rb +0 -83
  61. data/vendor/rack/lib/rack/handler/lsws.rb +0 -52
  62. data/vendor/rack/lib/rack/handler/scgi.rb +0 -57
  63. data/vendor/rack/lib/rack/handler/webrick.rb +0 -57
  64. data/vendor/rack/lib/rack/lint.rb +0 -394
  65. data/vendor/rack/lib/rack/lobster.rb +0 -65
  66. data/vendor/rack/lib/rack/mock.rb +0 -160
  67. data/vendor/rack/lib/rack/recursive.rb +0 -57
  68. data/vendor/rack/lib/rack/reloader.rb +0 -64
  69. data/vendor/rack/lib/rack/request.rb +0 -197
  70. data/vendor/rack/lib/rack/response.rb +0 -166
  71. data/vendor/rack/lib/rack/session/abstract/id.rb +0 -126
  72. data/vendor/rack/lib/rack/session/cookie.rb +0 -71
  73. data/vendor/rack/lib/rack/session/memcache.rb +0 -83
  74. data/vendor/rack/lib/rack/session/pool.rb +0 -67
  75. data/vendor/rack/lib/rack/showexceptions.rb +0 -344
  76. data/vendor/rack/lib/rack/showstatus.rb +0 -103
  77. data/vendor/rack/lib/rack/static.rb +0 -38
  78. data/vendor/rack/lib/rack/urlmap.rb +0 -48
  79. data/vendor/rack/lib/rack/utils.rb +0 -240
  80. data/vendor/rack/test/cgi/lighttpd.conf +0 -20
  81. data/vendor/rack/test/cgi/test +0 -9
  82. data/vendor/rack/test/cgi/test.fcgi +0 -7
  83. data/vendor/rack/test/cgi/test.ru +0 -7
  84. data/vendor/rack/test/spec_rack_auth_basic.rb +0 -69
  85. data/vendor/rack/test/spec_rack_auth_digest.rb +0 -169
  86. data/vendor/rack/test/spec_rack_builder.rb +0 -50
  87. data/vendor/rack/test/spec_rack_camping.rb +0 -47
  88. data/vendor/rack/test/spec_rack_cascade.rb +0 -50
  89. data/vendor/rack/test/spec_rack_cgi.rb +0 -91
  90. data/vendor/rack/test/spec_rack_commonlogger.rb +0 -32
  91. data/vendor/rack/test/spec_rack_fastcgi.rb +0 -91
  92. data/vendor/rack/test/spec_rack_file.rb +0 -40
  93. data/vendor/rack/test/spec_rack_lint.rb +0 -317
  94. data/vendor/rack/test/spec_rack_lobster.rb +0 -45
  95. data/vendor/rack/test/spec_rack_mock.rb +0 -152
  96. data/vendor/rack/test/spec_rack_mongrel.rb +0 -165
  97. data/vendor/rack/test/spec_rack_recursive.rb +0 -77
  98. data/vendor/rack/test/spec_rack_request.rb +0 -384
  99. data/vendor/rack/test/spec_rack_response.rb +0 -167
  100. data/vendor/rack/test/spec_rack_session_cookie.rb +0 -49
  101. data/vendor/rack/test/spec_rack_session_memcache.rb +0 -100
  102. data/vendor/rack/test/spec_rack_session_pool.rb +0 -84
  103. data/vendor/rack/test/spec_rack_showexceptions.rb +0 -21
  104. data/vendor/rack/test/spec_rack_showstatus.rb +0 -71
  105. data/vendor/rack/test/spec_rack_static.rb +0 -37
  106. data/vendor/rack/test/spec_rack_urlmap.rb +0 -175
  107. data/vendor/rack/test/spec_rack_utils.rb +0 -57
  108. data/vendor/rack/test/spec_rack_webrick.rb +0 -106
  109. data/vendor/rack/test/testrequest.rb +0 -43
@@ -19,49 +19,49 @@ context "Looking up a request" do
19
19
  specify "returns what's at the end" do
20
20
  block = Proc.new { 'Hello' }
21
21
  get '/', &block
22
-
22
+
23
23
  result = Sinatra.application.lookup(
24
24
  Rack::Request.new(
25
25
  'REQUEST_METHOD' => 'GET',
26
26
  'PATH_INFO' => '/'
27
27
  )
28
28
  )
29
-
29
+
30
30
  result.should.not.be.nil
31
31
  result.block.should.be block
32
32
  end
33
-
33
+
34
34
  specify "takes params in path" do
35
35
  block = Proc.new { 'Hello' }
36
36
  get '/:foo', &block
37
-
37
+
38
38
  result = Sinatra.application.lookup(
39
39
  Rack::Request.new(
40
40
  'REQUEST_METHOD' => 'GET',
41
41
  'PATH_INFO' => '/bar'
42
42
  )
43
43
  )
44
-
44
+
45
45
  result.should.not.be.nil
46
46
  result.block.should.be block
47
47
  result.params.should.equal "foo" => 'bar'
48
48
  end
49
-
49
+
50
50
  end
51
51
 
52
52
  context "An app returns" do
53
-
53
+
54
54
  setup do
55
55
  Sinatra.application = nil
56
56
  end
57
-
57
+
58
58
  specify "404 if no events found" do
59
59
  request = Rack::MockRequest.new(@app)
60
60
  get_it '/'
61
61
  should.be.not_found
62
62
  body.should.equal '<h1>Not Found</h1>'
63
63
  end
64
-
64
+
65
65
  specify "200 if success" do
66
66
  get '/' do
67
67
  'Hello World'
@@ -70,106 +70,249 @@ context "An app returns" do
70
70
  should.be.ok
71
71
  body.should.equal 'Hello World'
72
72
  end
73
-
73
+
74
74
  specify "an objects result from each if it has it" do
75
-
75
+
76
76
  get '/' do
77
77
  TesterWithEach.new
78
78
  end
79
-
79
+
80
80
  get_it '/'
81
81
  should.be.ok
82
82
  body.should.equal 'foobarbaz'
83
83
 
84
84
  end
85
-
85
+
86
86
  specify "the body set if set before the last" do
87
-
87
+
88
88
  get '/' do
89
89
  body 'Blake'
90
90
  'Mizerany'
91
91
  end
92
-
92
+
93
93
  get_it '/'
94
94
  should.be.ok
95
95
  body.should.equal 'Blake'
96
96
 
97
97
  end
98
-
98
+
99
+ end
100
+
101
+ context "Application#configure blocks" do
102
+
103
+ setup do
104
+ Sinatra.application = nil
105
+ end
106
+
107
+ specify "run when no environment specified" do
108
+ ref = false
109
+ configure { ref = true }
110
+ ref.should.equal true
111
+ end
112
+
113
+ specify "run when matching environment specified" do
114
+ ref = false
115
+ configure(:test) { ref = true }
116
+ ref.should.equal true
117
+ end
118
+
119
+ specify "do not run when no matching environment specified" do
120
+ configure(:foo) { flunk "block should not have been executed" }
121
+ configure(:development, :production, :foo) { flunk "block should not have been executed" }
122
+ end
123
+
124
+ specify "accept multiple environments" do
125
+ ref = false
126
+ configure(:foo, :test, :bar) { ref = true }
127
+ ref.should.equal true
128
+ end
129
+
130
+ end
131
+
132
+ context "Default Application Configuration" do
133
+
134
+ specify "includes 404 and 500 error handlers" do
135
+ Sinatra.application.errors.should.include(Sinatra::ServerError)
136
+ Sinatra.application.errors[Sinatra::ServerError].should.not.be.nil
137
+ Sinatra.application.errors.should.include(Sinatra::NotFound)
138
+ Sinatra.application.errors[Sinatra::NotFound].should.not.be.nil
139
+ end
140
+
141
+ specify "includes Static event" do
142
+ assert Sinatra.application.events[:get].any? { |e| Sinatra::Static === e }
143
+ end
144
+
99
145
  end
100
-
146
+
101
147
  context "Events in an app" do
102
-
148
+
103
149
  setup do
104
150
  Sinatra.application = nil
105
151
  end
106
-
152
+
107
153
  specify "evaluate in a clean context" do
108
154
  helpers do
109
155
  def foo
110
156
  'foo'
111
157
  end
112
158
  end
113
-
159
+
114
160
  get '/foo' do
115
161
  foo
116
162
  end
117
-
163
+
118
164
  get_it '/foo'
119
165
  should.be.ok
120
166
  body.should.equal 'foo'
121
167
  end
122
-
168
+
123
169
  specify "get access to request, response, and params" do
124
170
  get '/:foo' do
125
171
  params["foo"] + params["bar"]
126
172
  end
127
-
173
+
128
174
  get_it '/foo?bar=baz'
129
175
  should.be.ok
130
176
  body.should.equal 'foobaz'
131
177
  end
132
-
178
+
133
179
  specify "can filters by agent" do
134
-
180
+
135
181
  get '/', :agent => /Windows/ do
136
182
  request.env['HTTP_USER_AGENT']
137
183
  end
138
-
184
+
139
185
  get_it '/', :env => { :agent => 'Windows' }
140
186
  should.be.ok
141
187
  body.should.equal 'Windows'
142
188
 
143
- get_it '/', :agent => 'Mac'
189
+ get_it '/', :env => { :agent => 'Mac' }
144
190
  should.not.be.ok
145
191
 
146
192
  end
147
193
 
148
- specify "can filters by agent" do
149
-
194
+ specify "can use regex to get parts of user-agent" do
195
+
150
196
  get '/', :agent => /Windows (NT)/ do
151
197
  params[:agent].first
152
198
  end
153
-
199
+
154
200
  get_it '/', :env => { :agent => 'Windows NT' }
155
201
 
156
202
  body.should.equal 'NT'
157
203
 
158
204
  end
159
-
205
+
160
206
  specify "can deal with spaces in paths" do
161
-
207
+
162
208
  path = '/path with spaces'
163
-
209
+
164
210
  get path do
165
211
  "Look ma, a path with spaces!"
166
212
  end
167
-
213
+
168
214
  get_it URI.encode(path)
169
-
215
+
170
216
  body.should.equal "Look ma, a path with spaces!"
171
217
  end
172
-
218
+
219
+ specify "route based on host" do
220
+
221
+ get '/' do
222
+ 'asdf'
223
+ end
224
+
225
+ get_it '/'
226
+ assert ok?
227
+ assert_equal('asdf', body)
228
+
229
+ get '/foo', :host => 'foo.sinatrarb.com' do
230
+ 'in foo!'
231
+ end
232
+
233
+ get '/foo', :host => 'bar.sinatrarb.com' do
234
+ 'in bar!'
235
+ end
236
+
237
+ get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
238
+ assert ok?
239
+ assert_equal 'in foo!', body
240
+
241
+ get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com'
242
+ assert ok?
243
+ assert_equal 'in bar!', body
244
+
245
+ get_it '/foo'
246
+ assert not_found?
247
+
248
+ end
249
+
173
250
  end
174
251
 
175
252
 
253
+ context "Options in an app" do
254
+
255
+ setup do
256
+ Sinatra.application = nil
257
+ @app = Sinatra::application
258
+ end
259
+
260
+ specify "can be set singly on app" do
261
+ @app.set :foo, 1234
262
+ @app.options.foo.should.equal 1234
263
+ end
264
+
265
+ specify "can be set singly from top-level" do
266
+ set_option :foo, 1234
267
+ @app.options.foo.should.equal 1234
268
+ end
269
+
270
+ specify "can be set multiply on app" do
271
+ @app.options.foo.should.be.nil
272
+ @app.set :foo => 1234,
273
+ :bar => 'hello, world'
274
+ @app.options.foo.should.equal 1234
275
+ @app.options.bar.should.equal 'hello, world'
276
+ end
277
+
278
+ specify "can be set multiply from top-level" do
279
+ @app.options.foo.should.be.nil
280
+ set_options :foo => 1234,
281
+ :bar => 'hello, world'
282
+ @app.options.foo.should.equal 1234
283
+ @app.options.bar.should.equal 'hello, world'
284
+ end
285
+
286
+ specify "can be enabled on app" do
287
+ @app.options.foo.should.be.nil
288
+ @app.enable :sessions, :foo, :bar
289
+ @app.options.sessions.should.equal true
290
+ @app.options.foo.should.equal true
291
+ @app.options.bar.should.equal true
292
+ end
293
+
294
+ specify "can be enabled from top-level" do
295
+ @app.options.foo.should.be.nil
296
+ enable :sessions, :foo, :bar
297
+ @app.options.sessions.should.equal true
298
+ @app.options.foo.should.equal true
299
+ @app.options.bar.should.equal true
300
+ end
301
+
302
+ specify "can be disabled on app" do
303
+ @app.options.foo.should.be.nil
304
+ @app.disable :sessions, :foo, :bar
305
+ @app.options.sessions.should.equal false
306
+ @app.options.foo.should.equal false
307
+ @app.options.bar.should.equal false
308
+ end
309
+
310
+ specify "can be enabled from top-level" do
311
+ @app.options.foo.should.be.nil
312
+ disable :sessions, :foo, :bar
313
+ @app.options.sessions.should.equal false
314
+ @app.options.foo.should.equal false
315
+ @app.options.bar.should.equal false
316
+ end
317
+
318
+ end
@@ -1,67 +1,62 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- context "Custom Errors (in general)" do
3
+ context "Custom Errors" do
4
4
 
5
5
  setup do
6
6
  Sinatra.application = nil
7
7
  end
8
-
8
+
9
9
  specify "override the default 404" do
10
-
10
+
11
11
  get_it '/'
12
12
  should.be.not_found
13
13
  body.should.equal '<h1>Not Found</h1>'
14
-
14
+
15
15
  error Sinatra::NotFound do
16
16
  'Custom 404'
17
17
  end
18
-
18
+
19
19
  get_it '/'
20
20
  should.be.not_found
21
21
  body.should.equal 'Custom 404'
22
-
22
+
23
23
  end
24
-
24
+
25
25
  specify "override the default 500" do
26
26
  Sinatra.application.options.raise_errors = false
27
-
27
+
28
28
  get '/' do
29
29
  raise 'asdf'
30
30
  end
31
-
31
+
32
32
  get_it '/'
33
33
  status.should.equal 500
34
34
  body.should.equal '<h1>Internal Server Error</h1>'
35
-
36
-
35
+
36
+
37
37
  error do
38
38
  'Custom 500 for ' + request.env['sinatra.error'].message
39
39
  end
40
-
40
+
41
41
  get_it '/'
42
-
42
+
43
43
  get_it '/'
44
44
  status.should.equal 500
45
45
  body.should.equal 'Custom 500 for asdf'
46
-
46
+
47
47
  Sinatra.application.options.raise_errors = true
48
48
  end
49
-
49
+
50
50
  class UnmappedError < RuntimeError; end
51
-
51
+
52
52
  specify "should bring unmapped error back to the top" do
53
53
  get '/' do
54
54
  raise UnmappedError, 'test'
55
55
  end
56
-
56
+
57
57
  assert_raises(UnmappedError) do
58
58
  get_it '/'
59
59
  end
60
60
  end
61
61
 
62
62
  end
63
-
64
-
65
-
66
-
67
-
@@ -5,81 +5,101 @@ context "Erb" do
5
5
  setup do
6
6
  Sinatra.application = nil
7
7
  end
8
-
8
+
9
9
  context "without layouts" do
10
-
10
+
11
11
  setup do
12
12
  Sinatra.application = nil
13
13
  end
14
-
14
+
15
15
  specify "should render" do
16
-
16
+
17
17
  get '/no_layout' do
18
18
  erb '<%= 1 + 1 %>'
19
19
  end
20
-
20
+
21
21
  get_it '/no_layout'
22
22
  should.be.ok
23
23
  body.should == '2'
24
24
 
25
25
  end
26
+
27
+ specify "should take an options hash with :locals set with a string" do
28
+ get '/locals' do
29
+ erb '<%= foo %>', :locals => {:foo => "Bar"}
30
+ end
31
+
32
+ get_it '/locals'
33
+ should.be.ok
34
+ body.should == 'Bar'
35
+ end
36
+
37
+ specify "should take an options hash with :locals set with a complex object" do
38
+ get '/locals-complex' do
39
+ erb '<%= foo[0] %>', :locals => {:foo => ["foo", "bar", "baz"]}
40
+ end
41
+
42
+ get_it '/locals-complex'
43
+ should.be.ok
44
+ body.should == 'foo'
45
+ end
26
46
  end
27
-
47
+
28
48
  context "with layouts" do
29
49
 
30
50
  setup do
31
51
  Sinatra.application = nil
32
52
  end
33
-
53
+
34
54
  specify "can be inline" do
35
-
55
+
36
56
  layout do
37
57
  %Q{This is <%= yield %>!}
38
58
  end
39
-
59
+
40
60
  get '/lay' do
41
61
  erb 'Blake'
42
62
  end
43
-
63
+
44
64
  get_it '/lay'
45
65
  should.be.ok
46
66
  body.should.equal 'This is Blake!'
47
67
 
48
68
  end
49
-
69
+
50
70
  specify "can use named layouts" do
51
-
71
+
52
72
  layout :pretty do
53
73
  %Q{<h1><%= yield %></h1>}
54
74
  end
55
-
75
+
56
76
  get '/pretty' do
57
77
  erb 'Foo', :layout => :pretty
58
78
  end
59
-
79
+
60
80
  get '/not_pretty' do
61
81
  erb 'Bar'
62
82
  end
63
-
83
+
64
84
  get_it '/pretty'
65
85
  body.should.equal '<h1>Foo</h1>'
66
-
86
+
67
87
  get_it '/not_pretty'
68
88
  body.should.equal 'Bar'
69
-
89
+
70
90
  end
71
-
91
+
72
92
  specify "can be read from a file if they're not inlined" do
73
-
93
+
74
94
  get '/foo' do
75
95
  @title = 'Welcome to the Hello Program'
76
96
  erb 'Blake', :layout => :foo_layout,
77
97
  :views_directory => File.dirname(__FILE__) + "/views"
78
98
  end
79
-
99
+
80
100
  get_it '/foo'
81
101
  body.should.equal "Welcome to the Hello Program\nHi Blake\n"
82
-
102
+
83
103
  end
84
104
 
85
105
  end
@@ -112,5 +132,5 @@ context "Erb" do
112
132
  end
113
133
 
114
134
  end
115
-
135
+
116
136
  end