sinatra 0.9.6 → 1.0.a
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/CHANGES +83 -29
- data/README.jp.rdoc +552 -0
- data/README.rdoc +31 -9
- data/Rakefile +73 -91
- data/lib/sinatra.rb +0 -1
- data/lib/sinatra/base.rb +248 -269
- data/lib/sinatra/main.rb +3 -11
- data/lib/sinatra/tilt.rb +509 -0
- data/sinatra.gemspec +15 -49
- data/test/erubis_test.rb +82 -0
- data/test/extensions_test.rb +1 -1
- data/test/filter_test.rb +125 -3
- data/test/helpers_test.rb +59 -2
- data/test/mapped_error_test.rb +31 -0
- data/test/middleware_test.rb +1 -1
- data/test/request_test.rb +15 -0
- data/test/routing_test.rb +76 -0
- data/test/{options_test.rb → settings_test.rb} +46 -50
- data/test/static_test.rb +13 -0
- data/test/templates_test.rb +43 -10
- data/test/views/error.erubis +3 -0
- data/test/views/hello.erubis +1 -0
- data/test/views/layout2.erubis +2 -0
- metadata +61 -88
- data/compat/app_test.rb +0 -282
- data/compat/application_test.rb +0 -262
- data/compat/builder_test.rb +0 -101
- data/compat/compat_test.rb +0 -12
- data/compat/custom_error_test.rb +0 -62
- data/compat/erb_test.rb +0 -136
- data/compat/events_test.rb +0 -78
- data/compat/filter_test.rb +0 -30
- data/compat/haml_test.rb +0 -237
- data/compat/helper.rb +0 -34
- data/compat/mapped_error_test.rb +0 -72
- data/compat/pipeline_test.rb +0 -45
- data/compat/public/foo.xml +0 -1
- data/compat/sass_test.rb +0 -67
- data/compat/sessions_test.rb +0 -42
- data/compat/streaming_test.rb +0 -133
- data/compat/sym_params_test.rb +0 -18
- data/compat/template_test.rb +0 -30
- data/compat/use_in_file_templates_test.rb +0 -47
- data/compat/views/foo.builder +0 -1
- data/compat/views/foo.erb +0 -1
- data/compat/views/foo.haml +0 -1
- data/compat/views/foo.sass +0 -2
- data/compat/views/foo_layout.erb +0 -2
- data/compat/views/foo_layout.haml +0 -2
- data/compat/views/layout_test/foo.builder +0 -1
- data/compat/views/layout_test/foo.erb +0 -1
- data/compat/views/layout_test/foo.haml +0 -1
- data/compat/views/layout_test/foo.sass +0 -2
- data/compat/views/layout_test/layout.builder +0 -3
- data/compat/views/layout_test/layout.erb +0 -1
- data/compat/views/layout_test/layout.haml +0 -1
- data/compat/views/layout_test/layout.sass +0 -2
- data/compat/views/no_layout/no_layout.builder +0 -1
- data/compat/views/no_layout/no_layout.haml +0 -1
- data/lib/sinatra/compat.rb +0 -258
- data/lib/sinatra/test.rb +0 -129
- data/lib/sinatra/test/bacon.rb +0 -19
- data/lib/sinatra/test/rspec.rb +0 -13
- data/lib/sinatra/test/spec.rb +0 -11
- data/lib/sinatra/test/unit.rb +0 -13
- data/test/render_backtrace_test.rb +0 -145
- data/test/test_test.rb +0 -155
data/compat/events_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Simple Events" do
|
4
|
-
def simple_request_hash(method, path)
|
5
|
-
Rack::Request.new({
|
6
|
-
'REQUEST_METHOD' => method.to_s.upcase,
|
7
|
-
'PATH_INFO' => path
|
8
|
-
})
|
9
|
-
end
|
10
|
-
|
11
|
-
class MockResult < Struct.new(:block, :params)
|
12
|
-
end
|
13
|
-
|
14
|
-
def invoke_simple(path, request_path, &b)
|
15
|
-
params = nil
|
16
|
-
get path do
|
17
|
-
params = self.params
|
18
|
-
b.call if b
|
19
|
-
end
|
20
|
-
get_it request_path
|
21
|
-
MockResult.new(b, params)
|
22
|
-
end
|
23
|
-
|
24
|
-
setup { Sinatra.application = nil }
|
25
|
-
|
26
|
-
specify "return last value" do
|
27
|
-
block = Proc.new { 'Simple' }
|
28
|
-
result = invoke_simple('/', '/', &block)
|
29
|
-
result.should.not.be.nil
|
30
|
-
result.block.should.be block
|
31
|
-
result.params.should.equal Hash.new
|
32
|
-
end
|
33
|
-
|
34
|
-
specify "takes params in path" do
|
35
|
-
result = invoke_simple('/:foo/:bar', '/a/b')
|
36
|
-
result.should.not.be.nil
|
37
|
-
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
38
|
-
|
39
|
-
# unscapes
|
40
|
-
Sinatra.application = nil
|
41
|
-
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
|
42
|
-
result.should.not.be.nil
|
43
|
-
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
|
44
|
-
end
|
45
|
-
|
46
|
-
specify "takes optional params in path" do
|
47
|
-
result = invoke_simple('/?:foo?/?:bar?', '/a/b')
|
48
|
-
result.should.not.be.nil
|
49
|
-
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
50
|
-
|
51
|
-
Sinatra.application = nil
|
52
|
-
result = invoke_simple('/?:foo?/?:bar?', '/a/')
|
53
|
-
result.should.not.be.nil
|
54
|
-
result.params.should.equal "foo" => 'a', "bar" => nil
|
55
|
-
|
56
|
-
Sinatra.application = nil
|
57
|
-
result = invoke_simple('/?:foo?/?:bar?', '/a')
|
58
|
-
result.should.not.be.nil
|
59
|
-
result.params.should.equal "foo" => 'a', "bar" => nil
|
60
|
-
|
61
|
-
Sinatra.application = nil
|
62
|
-
result = invoke_simple('/:foo?/?:bar?', '/')
|
63
|
-
result.should.not.be.nil
|
64
|
-
result.params.should.equal "foo" => nil, "bar" => nil
|
65
|
-
end
|
66
|
-
|
67
|
-
specify "ignores to many /'s" do
|
68
|
-
result = invoke_simple('/x/y', '/x//y')
|
69
|
-
result.should.not.be.nil
|
70
|
-
end
|
71
|
-
|
72
|
-
specify "understands splat" do
|
73
|
-
invoke_simple('/foo/*', '/foo/bar').should.not.be.nil
|
74
|
-
invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil
|
75
|
-
invoke_simple('/foo/*', '/foo/baz').should.not.be.nil
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
data/compat/filter_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "before filters" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Sinatra.application = nil
|
7
|
-
@app = Sinatra.application
|
8
|
-
end
|
9
|
-
|
10
|
-
specify "should be executed in the order defined" do
|
11
|
-
invoked = 0x0
|
12
|
-
@app.before { invoked = 0x01 }
|
13
|
-
@app.before { invoked |= 0x02 }
|
14
|
-
@app.get('/') { 'Hello World' }
|
15
|
-
get_it '/'
|
16
|
-
should.be.ok
|
17
|
-
body.should.be == 'Hello World'
|
18
|
-
invoked.should.be == 0x03
|
19
|
-
end
|
20
|
-
|
21
|
-
specify "should be capable of modifying the request" do
|
22
|
-
@app.get('/foo') { 'foo' }
|
23
|
-
@app.get('/bar') { 'bar' }
|
24
|
-
@app.before { request.path_info = '/bar' }
|
25
|
-
get_it '/foo'
|
26
|
-
should.be.ok
|
27
|
-
body.should.be == 'bar'
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/compat/haml_test.rb
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Haml" do
|
4
|
-
include Mocha::API
|
5
|
-
|
6
|
-
setup do
|
7
|
-
Sinatra.application = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
context "without layouts" do
|
11
|
-
|
12
|
-
setup do
|
13
|
-
Sinatra.application = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
specify "should render" do
|
17
|
-
|
18
|
-
get '/no_layout' do
|
19
|
-
haml '== #{1+1}'
|
20
|
-
end
|
21
|
-
|
22
|
-
get_it '/no_layout'
|
23
|
-
should.be.ok
|
24
|
-
body.should == "2\n"
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with layouts" do
|
30
|
-
|
31
|
-
setup do
|
32
|
-
Sinatra.application = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
specify "can be inline" do
|
36
|
-
|
37
|
-
layout do
|
38
|
-
'== This is #{yield}!'
|
39
|
-
end
|
40
|
-
|
41
|
-
get '/lay' do
|
42
|
-
haml 'Blake'
|
43
|
-
end
|
44
|
-
|
45
|
-
get_it '/lay'
|
46
|
-
should.be.ok
|
47
|
-
body.should.equal "This is Blake\n!\n"
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
specify "can use named layouts" do
|
52
|
-
|
53
|
-
layout :pretty do
|
54
|
-
'%h1== #{yield}'
|
55
|
-
end
|
56
|
-
|
57
|
-
get '/pretty' do
|
58
|
-
haml 'Foo', :layout => :pretty
|
59
|
-
end
|
60
|
-
|
61
|
-
get '/not_pretty' do
|
62
|
-
haml 'Bar'
|
63
|
-
end
|
64
|
-
|
65
|
-
get_it '/pretty'
|
66
|
-
body.should.equal "<h1>Foo</h1>\n"
|
67
|
-
|
68
|
-
get_it '/not_pretty'
|
69
|
-
body.should.equal "Bar\n"
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
specify "can be read from a file if they're not inlined" do
|
74
|
-
|
75
|
-
get '/foo' do
|
76
|
-
@title = 'Welcome to the Hello Program'
|
77
|
-
haml 'Blake', :layout => :foo_layout,
|
78
|
-
:views_directory => File.dirname(__FILE__) + "/views"
|
79
|
-
end
|
80
|
-
|
81
|
-
get_it '/foo'
|
82
|
-
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
specify "can be read from file and layout from text" do
|
87
|
-
get '/foo' do
|
88
|
-
haml 'Test', :layout => '== Foo #{yield}'
|
89
|
-
end
|
90
|
-
|
91
|
-
get_it '/foo'
|
92
|
-
|
93
|
-
body.should.equal "Foo Test\n"
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
context "Templates (in general)" do
|
99
|
-
|
100
|
-
setup do
|
101
|
-
Sinatra.application = nil
|
102
|
-
end
|
103
|
-
|
104
|
-
specify "are read from files if Symbols" do
|
105
|
-
|
106
|
-
get '/from_file' do
|
107
|
-
@name = 'Alena'
|
108
|
-
haml :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
109
|
-
end
|
110
|
-
|
111
|
-
get_it '/from_file'
|
112
|
-
|
113
|
-
body.should.equal "You rock Alena!\n"
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
specify "use layout.ext by default if available" do
|
118
|
-
|
119
|
-
get '/' do
|
120
|
-
haml :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
121
|
-
end
|
122
|
-
|
123
|
-
get_it '/'
|
124
|
-
should.be.ok
|
125
|
-
body.should.equal "x This is foo!\n x\n"
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
specify "renders without layout" do
|
130
|
-
|
131
|
-
get '/' do
|
132
|
-
haml :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
|
133
|
-
end
|
134
|
-
|
135
|
-
get_it '/'
|
136
|
-
should.be.ok
|
137
|
-
body.should.equal "<h1>No Layout!</h1>\n"
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
specify "can render with no layout" do
|
142
|
-
layout do
|
143
|
-
"X\n= yield\nX"
|
144
|
-
end
|
145
|
-
|
146
|
-
get '/' do
|
147
|
-
haml 'blake', :layout => false
|
148
|
-
end
|
149
|
-
|
150
|
-
get_it '/'
|
151
|
-
|
152
|
-
body.should.equal "blake\n"
|
153
|
-
end
|
154
|
-
|
155
|
-
specify "raises error if template not found" do
|
156
|
-
get '/' do
|
157
|
-
haml :not_found
|
158
|
-
end
|
159
|
-
|
160
|
-
lambda { get_it '/' }.should.raise(Errno::ENOENT)
|
161
|
-
end
|
162
|
-
|
163
|
-
specify "use layout.ext by default if available" do
|
164
|
-
|
165
|
-
template :foo do
|
166
|
-
'asdf'
|
167
|
-
end
|
168
|
-
|
169
|
-
get '/' do
|
170
|
-
haml :foo, :layout => false,
|
171
|
-
:views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
172
|
-
end
|
173
|
-
|
174
|
-
get_it '/'
|
175
|
-
should.be.ok
|
176
|
-
body.should.equal "asdf\n"
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
describe 'Options passed to the HAML interpreter' do
|
183
|
-
setup do
|
184
|
-
Sinatra.application = nil
|
185
|
-
end
|
186
|
-
|
187
|
-
specify 'default to filename and line of caller' do
|
188
|
-
|
189
|
-
get '/' do
|
190
|
-
haml 'foo'
|
191
|
-
end
|
192
|
-
|
193
|
-
Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
|
194
|
-
:line => (__LINE__-4)}).returns(stub(:render => 'foo'))
|
195
|
-
|
196
|
-
get_it '/'
|
197
|
-
should.be.ok
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
specify 'can be configured by passing :options to haml' do
|
202
|
-
|
203
|
-
get '/' do
|
204
|
-
haml 'foo', :options => {:format => :html4}
|
205
|
-
end
|
206
|
-
|
207
|
-
Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
|
208
|
-
:line => (__LINE__-4), :format => :html4}).returns(stub(:render => 'foo'))
|
209
|
-
|
210
|
-
get_it '/'
|
211
|
-
should.be.ok
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
specify 'can be configured using set_option :haml' do
|
216
|
-
|
217
|
-
configure do
|
218
|
-
set_option :haml, :format => :html4,
|
219
|
-
:escape_html => true
|
220
|
-
end
|
221
|
-
|
222
|
-
get '/' do
|
223
|
-
haml 'foo'
|
224
|
-
end
|
225
|
-
|
226
|
-
Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
|
227
|
-
:line => (__LINE__-4), :format => :html4,
|
228
|
-
:escape_html => true}).returns(stub(:render => 'foo'))
|
229
|
-
|
230
|
-
get_it '/'
|
231
|
-
should.be.ok
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
data/compat/helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'mocha'
|
2
|
-
|
3
|
-
# disable warnings in compat specs.
|
4
|
-
$VERBOSE = nil
|
5
|
-
|
6
|
-
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
|
7
|
-
|
8
|
-
ENV['RACK_ENV'] ||= 'test'
|
9
|
-
|
10
|
-
require 'sinatra'
|
11
|
-
require 'sinatra/test'
|
12
|
-
require 'sinatra/test/unit'
|
13
|
-
require 'sinatra/test/spec'
|
14
|
-
|
15
|
-
module Sinatra::Test
|
16
|
-
# we need to remove the new test helper methods since they conflict with
|
17
|
-
# the top-level methods of the same name.
|
18
|
-
%w(get head post put delete).each do |verb|
|
19
|
-
remove_method verb
|
20
|
-
end
|
21
|
-
include Sinatra::Delegator
|
22
|
-
end
|
23
|
-
|
24
|
-
class Test::Unit::TestCase
|
25
|
-
include Mocha::API
|
26
|
-
include Sinatra::Test
|
27
|
-
|
28
|
-
PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS)
|
29
|
-
|
30
|
-
def setup
|
31
|
-
@app = lambda { |env| Sinatra::Application.call(env) }
|
32
|
-
mocha_teardown
|
33
|
-
end
|
34
|
-
end
|
data/compat/mapped_error_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class FooError < RuntimeError; end
|
4
|
-
|
5
|
-
context "Mapped errors" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
Sinatra.application = nil
|
9
|
-
Sinatra.application.options.raise_errors = false
|
10
|
-
end
|
11
|
-
|
12
|
-
specify "are rescued and run in context" do
|
13
|
-
|
14
|
-
error FooError do
|
15
|
-
'MAPPED ERROR!'
|
16
|
-
end
|
17
|
-
|
18
|
-
get '/' do
|
19
|
-
raise FooError
|
20
|
-
end
|
21
|
-
|
22
|
-
get_it '/'
|
23
|
-
|
24
|
-
should.be.server_error
|
25
|
-
body.should.equal 'MAPPED ERROR!'
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
specify "renders empty if no each method on result" do
|
30
|
-
|
31
|
-
error FooError do
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
get '/' do
|
36
|
-
raise FooError
|
37
|
-
end
|
38
|
-
|
39
|
-
get_it '/'
|
40
|
-
|
41
|
-
should.be.server_error
|
42
|
-
body.should.be.empty
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
specify "doesn't override status if set" do
|
47
|
-
|
48
|
-
error FooError do
|
49
|
-
status(200)
|
50
|
-
end
|
51
|
-
|
52
|
-
get '/' do
|
53
|
-
raise FooError
|
54
|
-
end
|
55
|
-
|
56
|
-
get_it '/'
|
57
|
-
|
58
|
-
should.be.ok
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
specify "raises errors when the raise_errors option is set" do
|
63
|
-
Sinatra.application.options.raise_errors = true
|
64
|
-
error FooError do
|
65
|
-
end
|
66
|
-
get '/' do
|
67
|
-
raise FooError
|
68
|
-
end
|
69
|
-
assert_raises(FooError) { get_it('/') }
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|