Syd-sinatra 0.9.0.2 → 0.9.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +9 -8
- data/README.rdoc +52 -81
- data/Rakefile +8 -59
- data/compat/app_test.rb +2 -1
- data/compat/streaming_test.rb +13 -1
- data/lib/sinatra/base.rb +129 -56
- data/lib/sinatra/compat.rb +12 -12
- data/lib/sinatra/main.rb +1 -6
- data/lib/sinatra/test.rb +14 -8
- data/lib/sinatra/test/bacon.rb +1 -1
- data/lib/sinatra/test/rspec.rb +3 -1
- data/lib/sinatra/test/unit.rb +1 -1
- data/sinatra.gemspec +2 -2
- data/test/filter_test.rb +24 -0
- data/test/helper.rb +24 -5
- data/test/helpers_test.rb +395 -333
- data/test/middleware_test.rb +2 -2
- data/test/options_test.rb +43 -0
- data/test/reload_test.rb +7 -0
- data/test/result_test.rb +10 -0
- data/test/routing_test.rb +98 -2
- data/test/static_test.rb +10 -0
- metadata +2 -2
data/test/middleware_test.rb
CHANGED
@@ -38,7 +38,7 @@ describe "Middleware" do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it "runs in the order defined" do
|
42
42
|
@app.use UpcaseMiddleware
|
43
43
|
@app.use DowncaseMiddleware
|
44
44
|
get '/Foo'
|
@@ -46,7 +46,7 @@ describe "Middleware" do
|
|
46
46
|
assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
it "resets the prebuilt pipeline when new middleware is added" do
|
50
50
|
@app.use UpcaseMiddleware
|
51
51
|
get '/Foo'
|
52
52
|
assert_equal "/FOO", body
|
data/test/options_test.rb
CHANGED
@@ -95,3 +95,46 @@ describe 'Options' do
|
|
95
95
|
assert_equal 'okay', body
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
describe 'Backtrace Cleaning (clean_trace option)' do
|
100
|
+
before do
|
101
|
+
@app = Class.new(Sinatra::Base)
|
102
|
+
end
|
103
|
+
|
104
|
+
def clean_backtrace(trace)
|
105
|
+
@app.new.send(:clean_backtrace, trace)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'is enabled by default' do
|
109
|
+
assert @app.clean_trace
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'does nothing when disabled' do
|
113
|
+
backtrace = [
|
114
|
+
"./lib/sinatra/base.rb",
|
115
|
+
"./myapp:42",
|
116
|
+
("#{Gem.dir}/some/lib.rb" if defined?(Gem))
|
117
|
+
].compact
|
118
|
+
@app.set :clean_trace, false
|
119
|
+
assert_equal backtrace, clean_backtrace(backtrace)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'removes sinatra lib paths from backtrace when enabled' do
|
123
|
+
backtrace = [
|
124
|
+
"./lib/sinatra/base.rb",
|
125
|
+
"./lib/sinatra/compat.rb:42",
|
126
|
+
"./lib/sinatra/main.rb:55 in `foo'"
|
127
|
+
]
|
128
|
+
assert clean_backtrace(backtrace).empty?
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'removes ./ prefix from backtrace paths when enabled' do
|
132
|
+
assert_equal ['myapp.rb:42'], clean_backtrace(['./myapp.rb:42'])
|
133
|
+
end
|
134
|
+
|
135
|
+
if defined?(Gem)
|
136
|
+
it 'removes gem lib paths from backtrace when enabled' do
|
137
|
+
assert clean_backtrace(["#{Gem.dir}/some/lib"]).empty?
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/test/reload_test.rb
CHANGED
@@ -34,6 +34,13 @@ describe "Reloading" do
|
|
34
34
|
assert_same false, @app.reload?
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'is disabled when app_file is a rackup (.ru) file' do
|
38
|
+
@app.set :app_file, __FILE__.sub(/\.rb$/, '.ru')
|
39
|
+
@app.set :environment, :development
|
40
|
+
assert !@app.reload
|
41
|
+
assert_same false, @app.reload?
|
42
|
+
end
|
43
|
+
|
37
44
|
it 'can be turned off explicitly' do
|
38
45
|
@app.set :app_file, __FILE__
|
39
46
|
@app.set :environment, :development
|
data/test/result_test.rb
CHANGED
@@ -76,6 +76,16 @@ describe 'Result Handling' do
|
|
76
76
|
assert_equal 'formula of', body
|
77
77
|
end
|
78
78
|
|
79
|
+
it "raises a TypeError when result is a non two or three tuple Array" do
|
80
|
+
mock_app {
|
81
|
+
get '/' do
|
82
|
+
[409, 'formula of', 'something else', 'even more']
|
83
|
+
end
|
84
|
+
}
|
85
|
+
|
86
|
+
assert_raise(TypeError) { get '/' }
|
87
|
+
end
|
88
|
+
|
79
89
|
it "sets status when result is a Fixnum status code" do
|
80
90
|
mock_app {
|
81
91
|
get('/') { 205 }
|
data/test/routing_test.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
+
# Helper method for easy route pattern matching testing
|
4
|
+
def route_def(pattern)
|
5
|
+
mock_app { get(pattern) { } }
|
6
|
+
end
|
7
|
+
|
3
8
|
describe "Routing" do
|
4
|
-
%w[get put post delete
|
9
|
+
%w[get put post delete].each do |verb|
|
5
10
|
it "defines #{verb.upcase} request handlers with #{verb}" do
|
6
11
|
mock_app {
|
7
12
|
send verb, '/hello' do
|
@@ -16,6 +21,21 @@ describe "Routing" do
|
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
24
|
+
it "defines HEAD request handlers with HEAD" do
|
25
|
+
mock_app {
|
26
|
+
head '/hello' do
|
27
|
+
response['X-Hello'] = 'World!'
|
28
|
+
'remove me'
|
29
|
+
end
|
30
|
+
}
|
31
|
+
|
32
|
+
request = Rack::MockRequest.new(@app)
|
33
|
+
response = request.request('HEAD', '/hello', {})
|
34
|
+
assert response.ok?
|
35
|
+
assert_equal 'World!', response['X-Hello']
|
36
|
+
assert_equal '', response.body
|
37
|
+
end
|
38
|
+
|
19
39
|
it "404s when no route satisfies the request" do
|
20
40
|
mock_app {
|
21
41
|
get('/foo') { }
|
@@ -119,6 +139,38 @@ describe "Routing" do
|
|
119
139
|
assert ok?
|
120
140
|
end
|
121
141
|
|
142
|
+
it "literally matches . in paths" do
|
143
|
+
route_def '/test.bar'
|
144
|
+
|
145
|
+
get '/test.bar'
|
146
|
+
assert ok?
|
147
|
+
get 'test0bar'
|
148
|
+
assert not_found?
|
149
|
+
end
|
150
|
+
|
151
|
+
it "literally matches $ in paths" do
|
152
|
+
route_def '/test$/'
|
153
|
+
|
154
|
+
get '/test$/'
|
155
|
+
assert ok?
|
156
|
+
end
|
157
|
+
|
158
|
+
it "literally matches + in paths" do
|
159
|
+
route_def '/te+st/'
|
160
|
+
|
161
|
+
get '/te+st/'
|
162
|
+
assert ok?
|
163
|
+
get '/teeeeeeest/'
|
164
|
+
assert not_found?
|
165
|
+
end
|
166
|
+
|
167
|
+
it "literally matches () in paths" do
|
168
|
+
route_def '/test(bar)/'
|
169
|
+
|
170
|
+
get '/test(bar)/'
|
171
|
+
assert ok?
|
172
|
+
end
|
173
|
+
|
122
174
|
it "supports basic nested params" do
|
123
175
|
mock_app {
|
124
176
|
get '/hi' do
|
@@ -171,7 +223,22 @@ describe "Routing" do
|
|
171
223
|
'looks good'
|
172
224
|
end
|
173
225
|
}
|
174
|
-
get "/foo?#{
|
226
|
+
get "/foo?#{build_query(input)}"
|
227
|
+
assert ok?
|
228
|
+
assert_equal 'looks good', body
|
229
|
+
end
|
230
|
+
|
231
|
+
it "preserves non-nested params" do
|
232
|
+
mock_app {
|
233
|
+
get '/foo' do
|
234
|
+
assert_equal "2", params["article_id"]
|
235
|
+
assert_equal "awesome", params['comment']['body']
|
236
|
+
assert_nil params['comment[body]']
|
237
|
+
'looks good'
|
238
|
+
end
|
239
|
+
}
|
240
|
+
|
241
|
+
get '/foo?article_id=2&comment[body]=awesome'
|
175
242
|
assert ok?
|
176
243
|
assert_equal 'looks good', body
|
177
244
|
end
|
@@ -226,6 +293,11 @@ describe "Routing" do
|
|
226
293
|
assert_equal 'right on', body
|
227
294
|
end
|
228
295
|
|
296
|
+
it 'raises a TypeError when pattern is not a String or Regexp' do
|
297
|
+
@app = mock_app
|
298
|
+
assert_raise(TypeError) { @app.get(42){} }
|
299
|
+
end
|
300
|
+
|
229
301
|
it "returns response immediately on halt" do
|
230
302
|
mock_app {
|
231
303
|
get '/' do
|
@@ -239,6 +311,30 @@ describe "Routing" do
|
|
239
311
|
assert_equal 'Hello World', body
|
240
312
|
end
|
241
313
|
|
314
|
+
it "halts with a response tuple" do
|
315
|
+
mock_app {
|
316
|
+
get '/' do
|
317
|
+
halt 295, {'Content-Type' => 'text/plain'}, 'Hello World'
|
318
|
+
end
|
319
|
+
}
|
320
|
+
|
321
|
+
get '/'
|
322
|
+
assert_equal 295, status
|
323
|
+
assert_equal 'text/plain', response['Content-Type']
|
324
|
+
assert_equal 'Hello World', body
|
325
|
+
end
|
326
|
+
|
327
|
+
it "halts with an array of strings" do
|
328
|
+
mock_app {
|
329
|
+
get '/' do
|
330
|
+
halt %w[Hello World How Are You]
|
331
|
+
end
|
332
|
+
}
|
333
|
+
|
334
|
+
get '/'
|
335
|
+
assert_equal 'HelloWorldHowAreYou', body
|
336
|
+
end
|
337
|
+
|
242
338
|
it "transitions to the next matching route on pass" do
|
243
339
|
mock_app {
|
244
340
|
get '/:foo' do
|
data/test/static_test.rb
CHANGED
@@ -18,6 +18,16 @@ describe 'Static' do
|
|
18
18
|
assert response.headers.include?('Last-Modified')
|
19
19
|
end
|
20
20
|
|
21
|
+
it 'produces a body that can be iterated over multiple times' do
|
22
|
+
env = Rack::MockRequest.env_for("/#{F.basename(__FILE__)}")
|
23
|
+
status, headers, body = @app.call(env)
|
24
|
+
buf1, buf2 = [], []
|
25
|
+
body.each { |part| buf1 << part }
|
26
|
+
body.each { |part| buf2 << part }
|
27
|
+
assert_equal buf1.join, buf2.join
|
28
|
+
assert_equal File.read(__FILE__), buf1.join
|
29
|
+
end
|
30
|
+
|
21
31
|
it 'serves HEAD requests for files in the public directory' do
|
22
32
|
head "/#{F.basename(__FILE__)}"
|
23
33
|
assert ok?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Syd-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0.
|
4
|
+
version: 0.9.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Mizerany
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-25 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|