darkhelmet-sinatra 0.9.1.1 → 0.10.1

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 (88) hide show
  1. data/AUTHORS +2 -0
  2. data/CHANGES +180 -0
  3. data/LICENSE +1 -1
  4. data/README.jp.rdoc +552 -0
  5. data/README.rdoc +177 -38
  6. data/Rakefile +18 -25
  7. data/lib/sinatra.rb +1 -2
  8. data/lib/sinatra/base.rb +405 -305
  9. data/lib/sinatra/main.rb +5 -24
  10. data/lib/sinatra/showexceptions.rb +303 -0
  11. data/lib/sinatra/tilt.rb +509 -0
  12. data/sinatra.gemspec +21 -51
  13. data/test/base_test.rb +123 -93
  14. data/test/builder_test.rb +2 -1
  15. data/test/contest.rb +64 -0
  16. data/test/erb_test.rb +1 -1
  17. data/test/erubis_test.rb +82 -0
  18. data/test/extensions_test.rb +24 -8
  19. data/test/filter_test.rb +99 -3
  20. data/test/haml_test.rb +25 -3
  21. data/test/helper.rb +43 -48
  22. data/test/helpers_test.rb +500 -424
  23. data/test/mapped_error_test.rb +163 -137
  24. data/test/middleware_test.rb +3 -3
  25. data/test/request_test.rb +16 -1
  26. data/test/response_test.rb +2 -2
  27. data/test/result_test.rb +1 -1
  28. data/test/route_added_hook_test.rb +59 -0
  29. data/test/routing_test.rb +170 -22
  30. data/test/sass_test.rb +44 -1
  31. data/test/server_test.rb +19 -13
  32. data/test/sinatra_test.rb +1 -1
  33. data/test/static_test.rb +9 -2
  34. data/test/templates_test.rb +78 -11
  35. data/test/views/error.builder +3 -0
  36. data/test/views/error.erb +3 -0
  37. data/test/views/error.erubis +3 -0
  38. data/test/views/error.haml +3 -0
  39. data/test/views/error.sass +2 -0
  40. data/test/views/foo/hello.test +1 -0
  41. data/test/views/hello.erubis +1 -0
  42. data/test/views/layout2.erubis +2 -0
  43. metadata +37 -55
  44. data/compat/app_test.rb +0 -282
  45. data/compat/application_test.rb +0 -262
  46. data/compat/builder_test.rb +0 -101
  47. data/compat/compat_test.rb +0 -12
  48. data/compat/custom_error_test.rb +0 -62
  49. data/compat/erb_test.rb +0 -136
  50. data/compat/events_test.rb +0 -78
  51. data/compat/filter_test.rb +0 -30
  52. data/compat/haml_test.rb +0 -233
  53. data/compat/helper.rb +0 -30
  54. data/compat/mapped_error_test.rb +0 -72
  55. data/compat/pipeline_test.rb +0 -45
  56. data/compat/public/foo.xml +0 -1
  57. data/compat/sass_test.rb +0 -57
  58. data/compat/sessions_test.rb +0 -42
  59. data/compat/streaming_test.rb +0 -133
  60. data/compat/sym_params_test.rb +0 -19
  61. data/compat/template_test.rb +0 -30
  62. data/compat/use_in_file_templates_test.rb +0 -47
  63. data/compat/views/foo.builder +0 -1
  64. data/compat/views/foo.erb +0 -1
  65. data/compat/views/foo.haml +0 -1
  66. data/compat/views/foo.sass +0 -2
  67. data/compat/views/foo_layout.erb +0 -2
  68. data/compat/views/foo_layout.haml +0 -2
  69. data/compat/views/layout_test/foo.builder +0 -1
  70. data/compat/views/layout_test/foo.erb +0 -1
  71. data/compat/views/layout_test/foo.haml +0 -1
  72. data/compat/views/layout_test/foo.sass +0 -2
  73. data/compat/views/layout_test/layout.builder +0 -3
  74. data/compat/views/layout_test/layout.erb +0 -1
  75. data/compat/views/layout_test/layout.haml +0 -1
  76. data/compat/views/layout_test/layout.sass +0 -2
  77. data/compat/views/no_layout/no_layout.builder +0 -1
  78. data/compat/views/no_layout/no_layout.haml +0 -1
  79. data/lib/sinatra/compat.rb +0 -250
  80. data/lib/sinatra/test.rb +0 -126
  81. data/lib/sinatra/test/bacon.rb +0 -19
  82. data/lib/sinatra/test/rspec.rb +0 -13
  83. data/lib/sinatra/test/spec.rb +0 -11
  84. data/lib/sinatra/test/unit.rb +0 -13
  85. data/test/data/reload_app_file.rb +0 -3
  86. data/test/options_test.rb +0 -374
  87. data/test/reload_test.rb +0 -68
  88. data/test/test_test.rb +0 -144
@@ -1,282 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "Sinatra" do
4
-
5
- setup do
6
- Sinatra.application = nil
7
- end
8
-
9
- specify "should put all DSL methods on (main)" do
10
- object = Object.new
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)
14
- end
15
- end
16
-
17
- specify "should handle result of nil" do
18
- get '/' do
19
- nil
20
- end
21
-
22
- get_it '/'
23
- should.be.ok
24
- body.should == ''
25
- end
26
-
27
- specify "handles events" do
28
- get '/:name' do
29
- 'Hello ' + params["name"]
30
- end
31
-
32
- get_it '/Blake'
33
-
34
- should.be.ok
35
- body.should.equal 'Hello Blake'
36
- end
37
-
38
-
39
- specify "handles splats" do
40
- get '/hi/*' do
41
- params["splat"].kind_of?(Array).should.equal true
42
- params["splat"].first
43
- end
44
-
45
- get_it '/hi/Blake'
46
-
47
- should.be.ok
48
- body.should.equal 'Blake'
49
- end
50
-
51
- specify "handles multiple splats" do
52
- get '/say/*/to/*' do
53
- params["splat"].join(' ')
54
- end
55
-
56
- get_it '/say/hello/to/world'
57
-
58
- should.be.ok
59
- body.should.equal 'hello world'
60
- end
61
-
62
- specify "allow empty splats" do
63
- get '/say/*/to*/*' do
64
- params["splat"].join(' ')
65
- end
66
-
67
- get_it '/say/hello/to/world'
68
-
69
- should.be.ok
70
- body.should.equal 'hello world' # second splat is empty
71
-
72
- get_it '/say/hello/tomy/world'
73
-
74
- should.be.ok
75
- body.should.equal 'hello my world'
76
- end
77
-
78
- specify "gives access to underlying response header Hash" do
79
- get '/' do
80
- header['X-Test'] = 'Is this thing on?'
81
- headers 'X-Test2' => 'Foo', 'X-Test3' => 'Bar'
82
- ''
83
- end
84
-
85
- get_it '/'
86
- should.be.ok
87
- headers.should.include 'X-Test'
88
- headers['X-Test'].should.equal 'Is this thing on?'
89
- headers.should.include 'X-Test3'
90
- headers['X-Test3'].should.equal 'Bar'
91
- end
92
-
93
- specify "follows redirects" do
94
- get '/' do
95
- redirect '/blake'
96
- end
97
-
98
- get '/blake' do
99
- 'Mizerany'
100
- end
101
-
102
- get_it '/'
103
- should.be.redirection
104
- body.should.equal ''
105
-
106
- follow!
107
- should.be.ok
108
- body.should.equal 'Mizerany'
109
- end
110
-
111
- specify "renders a body with a redirect" do
112
- helpers do
113
- def foo ; 'blah' ; end
114
- end
115
- get "/" do
116
- redirect 'foo', :foo
117
- end
118
- get_it '/'
119
- should.be.redirection
120
- headers['Location'].should.equal 'foo'
121
- body.should.equal 'blah'
122
- end
123
-
124
- specify "redirects permanently with 301 status code" do
125
- get "/" do
126
- redirect 'foo', 301
127
- end
128
- get_it '/'
129
- should.be.redirection
130
- headers['Location'].should.equal 'foo'
131
- status.should.equal 301
132
- body.should.be.empty
133
- end
134
-
135
- specify "stop sets content and ends event" do
136
- get '/set_body' do
137
- stop 'Hello!'
138
- stop 'World!'
139
- fail 'stop should have halted'
140
- end
141
-
142
- get_it '/set_body'
143
-
144
- should.be.ok
145
- body.should.equal 'Hello!'
146
-
147
- end
148
-
149
- specify "should easily set response Content-Type" do
150
- get '/foo.html' do
151
- content_type 'text/html', :charset => 'utf-8'
152
- "<h1>Hello, World</h1>"
153
- end
154
-
155
- get_it '/foo.html'
156
- should.be.ok
157
- headers['Content-Type'].should.equal 'text/html;charset=utf-8'
158
- body.should.equal '<h1>Hello, World</h1>'
159
-
160
- get '/foo_test.xml' do
161
- content_type :xml
162
- "<feed></feed>"
163
- end
164
-
165
- get_it '/foo_test.xml'
166
- should.be.ok
167
- headers['Content-Type'].should.equal 'application/xml'
168
- body.should.equal '<feed></feed>'
169
- end
170
-
171
- specify "supports conditional GETs with last_modified" do
172
- modified_at = Time.now
173
- get '/maybe' do
174
- last_modified modified_at
175
- 'response body, maybe'
176
- end
177
-
178
- get_it '/maybe'
179
- should.be.ok
180
- body.should.equal 'response body, maybe'
181
-
182
- get_it '/maybe', :env => { 'HTTP_IF_MODIFIED_SINCE' => modified_at.httpdate }
183
- status.should.equal 304
184
- body.should.equal ''
185
- end
186
-
187
- specify "supports conditional GETs with entity_tag" do
188
- get '/strong' do
189
- entity_tag 'FOO'
190
- 'foo response'
191
- end
192
-
193
- get_it '/strong'
194
- should.be.ok
195
- body.should.equal 'foo response'
196
-
197
- get_it '/strong', {},
198
- 'HTTP_IF_NONE_MATCH' => '"BAR"'
199
- should.be.ok
200
- body.should.equal 'foo response'
201
-
202
- get_it '/strong', {},
203
- 'HTTP_IF_NONE_MATCH' => '"FOO"'
204
- status.should.equal 304
205
- body.should.equal ''
206
-
207
- get_it '/strong', {},
208
- 'HTTP_IF_NONE_MATCH' => '"BAR", *'
209
- status.should.equal 304
210
- body.should.equal ''
211
- end
212
-
213
- specify "delegates HEAD requests to GET handlers" do
214
- get '/invisible' do
215
- "I am invisible to the world"
216
- end
217
-
218
- head_it '/invisible'
219
- should.be.ok
220
- body.should.not.equal "I am invisible to the world"
221
- body.should.equal ''
222
- end
223
-
224
-
225
- specify "supports PUT" do
226
- put '/' do
227
- 'puted'
228
- end
229
- put_it '/'
230
- assert_equal 'puted', body
231
- end
232
-
233
- specify "rewrites POSTs with _method param to PUT" do
234
- put '/' do
235
- 'puted'
236
- end
237
- post_it '/', :_method => 'PUT'
238
- assert_equal 'puted', body
239
- end
240
-
241
- specify "rewrites POSTs with lowercase _method param to PUT" do
242
- put '/' do
243
- 'puted'
244
- end
245
- post_it '/', :_method => 'put'
246
- body.should.equal 'puted'
247
- end
248
-
249
- specify "does not rewrite GETs with _method param to PUT" do
250
- get '/' do
251
- 'getted'
252
- end
253
- get_it '/', :_method => 'put'
254
- should.be.ok
255
- body.should.equal 'getted'
256
- end
257
-
258
- specify "ignores _method query string parameter on non-POST requests" do
259
- post '/' do
260
- 'posted'
261
- end
262
- put '/' do
263
- 'booo'
264
- end
265
- post_it "/?_method=PUT"
266
- should.be.ok
267
- body.should.equal 'posted'
268
- end
269
-
270
- specify "does not read body if content type is not url encoded" do
271
- post '/foo.xml' do
272
- request.env['CONTENT_TYPE'].should.be == 'application/xml'
273
- request.content_type.should.be == 'application/xml'
274
- request.body.read
275
- end
276
-
277
- post_it '/foo.xml', '<foo></foo>', :content_type => 'application/xml'
278
- @response.should.be.ok
279
- @response.body.should.be == '<foo></foo>'
280
- end
281
-
282
- end
@@ -1,262 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- require 'uri'
4
-
5
- class TesterWithEach
6
- def each
7
- yield 'foo'
8
- yield 'bar'
9
- yield 'baz'
10
- end
11
- end
12
-
13
- context "An app returns" do
14
-
15
- setup do
16
- Sinatra.application = nil
17
- end
18
-
19
- specify "404 if no events found" do
20
- request = Rack::MockRequest.new(@app)
21
- get_it '/'
22
- should.be.not_found
23
- body.should.equal '<h1>Not Found</h1>'
24
- end
25
-
26
- specify "200 if success" do
27
- get '/' do
28
- 'Hello World'
29
- end
30
- get_it '/'
31
- should.be.ok
32
- body.should.equal 'Hello World'
33
- end
34
-
35
- specify "an objects result from each if it has it" do
36
-
37
- get '/' do
38
- TesterWithEach.new
39
- end
40
-
41
- get_it '/'
42
- should.be.ok
43
- body.should.equal 'foobarbaz'
44
-
45
- end
46
-
47
- specify "404 if NotFound is raised" do
48
-
49
- get '/' do
50
- raise Sinatra::NotFound
51
- end
52
-
53
- get_it '/'
54
- should.be.not_found
55
-
56
- end
57
-
58
- end
59
-
60
- context "Application#configure blocks" do
61
-
62
- setup do
63
- Sinatra.application = nil
64
- end
65
-
66
- specify "run when no environment specified" do
67
- ref = false
68
- configure { ref = true }
69
- ref.should.equal true
70
- end
71
-
72
- specify "run when matching environment specified" do
73
- ref = false
74
- configure(:test) { ref = true }
75
- ref.should.equal true
76
- end
77
-
78
- specify "do not run when no matching environment specified" do
79
- configure(:foo) { flunk "block should not have been executed" }
80
- configure(:development, :production, :foo) { flunk "block should not have been executed" }
81
- end
82
-
83
- specify "accept multiple environments" do
84
- ref = false
85
- configure(:foo, :test, :bar) { ref = true }
86
- ref.should.equal true
87
- end
88
-
89
- end
90
-
91
- context "Events in an app" do
92
-
93
- setup do
94
- Sinatra.application = nil
95
- end
96
-
97
- specify "evaluate in a clean context" do
98
- helpers do
99
- def foo
100
- 'foo'
101
- end
102
- end
103
-
104
- get '/foo' do
105
- foo
106
- end
107
-
108
- get_it '/foo'
109
- should.be.ok
110
- body.should.equal 'foo'
111
- end
112
-
113
- specify "get access to request, response, and params" do
114
- get '/:foo' do
115
- params["foo"] + params["bar"]
116
- end
117
-
118
- get_it '/foo?bar=baz'
119
- should.be.ok
120
- body.should.equal 'foobaz'
121
- end
122
-
123
- specify "can filters by agent" do
124
-
125
- get '/', :agent => /Windows/ do
126
- request.env['HTTP_USER_AGENT']
127
- end
128
-
129
- get_it '/', :env => { :agent => 'Windows' }
130
- should.be.ok
131
- body.should.equal 'Windows'
132
-
133
- get_it '/', :env => { :agent => 'Mac' }
134
- should.not.be.ok
135
-
136
- end
137
-
138
- specify "can use regex to get parts of user-agent" do
139
-
140
- get '/', :agent => /Windows (NT)/ do
141
- params[:agent].first
142
- end
143
-
144
- get_it '/', :env => { :agent => 'Windows NT' }
145
-
146
- body.should.equal 'NT'
147
-
148
- end
149
-
150
- specify "can deal with spaces in paths" do
151
-
152
- path = '/path with spaces'
153
-
154
- get path do
155
- "Look ma, a path with spaces!"
156
- end
157
-
158
- get_it URI.encode(path)
159
-
160
- body.should.equal "Look ma, a path with spaces!"
161
- end
162
-
163
- specify "route based on host" do
164
-
165
- get '/' do
166
- 'asdf'
167
- end
168
-
169
- get_it '/'
170
- assert ok?
171
- assert_equal('asdf', body)
172
-
173
- get '/foo', :host => 'foo.sinatrarb.com' do
174
- 'in foo!'
175
- end
176
-
177
- get '/foo', :host => 'bar.sinatrarb.com' do
178
- 'in bar!'
179
- end
180
-
181
- get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
182
- assert ok?
183
- assert_equal 'in foo!', body
184
-
185
- get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com'
186
- assert ok?
187
- assert_equal 'in bar!', body
188
-
189
- get_it '/foo'
190
- assert not_found?
191
-
192
- end
193
-
194
- end
195
-
196
-
197
- context "Options in an app" do
198
-
199
- setup do
200
- Sinatra.application = nil
201
- @app = Sinatra::application
202
- end
203
-
204
- specify "can be set singly on app" do
205
- @app.set :foo, 1234
206
- @app.options.foo.should.equal 1234
207
- end
208
-
209
- specify "can be set singly from top-level" do
210
- set_option :foo, 1234
211
- @app.options.foo.should.equal 1234
212
- end
213
-
214
- specify "can be set multiply on app" do
215
- @app.options.foo.should.be.nil
216
- @app.set :foo => 1234,
217
- :bar => 'hello, world'
218
- @app.options.foo.should.equal 1234
219
- @app.options.bar.should.equal 'hello, world'
220
- end
221
-
222
- specify "can be set multiply from top-level" do
223
- @app.options.foo.should.be.nil
224
- set_options :foo => 1234,
225
- :bar => 'hello, world'
226
- @app.options.foo.should.equal 1234
227
- @app.options.bar.should.equal 'hello, world'
228
- end
229
-
230
- specify "can be enabled on app" do
231
- @app.options.foo.should.be.nil
232
- @app.enable :sessions, :foo, :bar
233
- @app.options.sessions.should.equal true
234
- @app.options.foo.should.equal true
235
- @app.options.bar.should.equal true
236
- end
237
-
238
- specify "can be enabled from top-level" do
239
- @app.options.foo.should.be.nil
240
- enable :sessions, :foo, :bar
241
- @app.options.sessions.should.equal true
242
- @app.options.foo.should.equal true
243
- @app.options.bar.should.equal true
244
- end
245
-
246
- specify "can be disabled on app" do
247
- @app.options.foo.should.be.nil
248
- @app.disable :sessions, :foo, :bar
249
- @app.options.sessions.should.equal false
250
- @app.options.foo.should.equal false
251
- @app.options.bar.should.equal false
252
- end
253
-
254
- specify "can be enabled from top-level" do
255
- @app.options.foo.should.be.nil
256
- disable :sessions, :foo, :bar
257
- @app.options.sessions.should.equal false
258
- @app.options.foo.should.equal false
259
- @app.options.bar.should.equal false
260
- end
261
-
262
- end