sinatra 0.3.3 → 0.9.0
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.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/AUTHORS +40 -0
- data/CHANGES +189 -0
- data/README.rdoc +146 -117
- data/Rakefile +33 -10
- data/{test → compat}/app_test.rb +11 -10
- data/{test → compat}/application_test.rb +10 -5
- data/compat/builder_test.rb +101 -0
- data/{test → compat}/custom_error_test.rb +0 -0
- data/compat/erb_test.rb +136 -0
- data/{test → compat}/events_test.rb +16 -3
- data/compat/filter_test.rb +30 -0
- data/compat/haml_test.rb +233 -0
- data/compat/helper.rb +30 -0
- data/compat/mapped_error_test.rb +72 -0
- data/{test → compat}/pipeline_test.rb +9 -4
- data/{test → compat}/public/foo.xml +0 -0
- data/compat/sass_test.rb +57 -0
- data/{test → compat}/sessions_test.rb +0 -0
- data/{test → compat}/streaming_test.rb +4 -1
- data/{test → compat}/sym_params_test.rb +0 -0
- data/{test → compat}/template_test.rb +0 -0
- data/{test → compat}/use_in_file_templates_test.rb +0 -0
- data/{test → compat}/views/foo.builder +0 -0
- data/{test → compat}/views/foo.erb +0 -0
- data/{test → compat}/views/foo.haml +0 -0
- data/{test → compat}/views/foo.sass +0 -0
- data/{test → compat}/views/foo_layout.erb +0 -0
- data/{test → compat}/views/foo_layout.haml +0 -0
- data/{test → compat}/views/layout_test/foo.builder +0 -0
- data/{test → compat}/views/layout_test/foo.erb +0 -0
- data/{test → compat}/views/layout_test/foo.haml +0 -0
- data/{test → compat}/views/layout_test/foo.sass +0 -0
- data/{test → compat}/views/layout_test/layout.builder +0 -0
- data/{test → compat}/views/layout_test/layout.erb +0 -0
- data/{test → compat}/views/layout_test/layout.haml +0 -0
- data/{test → compat}/views/layout_test/layout.sass +0 -0
- data/{test → compat}/views/no_layout/no_layout.builder +0 -0
- data/{test → compat}/views/no_layout/no_layout.haml +0 -0
- data/lib/sinatra.rb +6 -1484
- data/lib/sinatra/base.rb +838 -0
- data/lib/sinatra/compat.rb +239 -0
- data/{images → lib/sinatra/images}/404.png +0 -0
- data/{images → lib/sinatra/images}/500.png +0 -0
- data/lib/sinatra/main.rb +48 -0
- data/lib/sinatra/test.rb +114 -0
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +7 -8
- data/lib/sinatra/test/spec.rb +3 -4
- data/lib/sinatra/test/unit.rb +3 -5
- data/sinatra.gemspec +68 -35
- data/test/base_test.rb +68 -0
- data/test/builder_test.rb +50 -87
- data/test/data/reload_app_file.rb +3 -0
- data/test/erb_test.rb +38 -124
- data/test/filter_test.rb +27 -22
- data/test/haml_test.rb +51 -216
- data/test/helper.rb +22 -6
- data/test/helpers_test.rb +361 -0
- data/test/mapped_error_test.rb +137 -49
- data/test/middleware_test.rb +58 -0
- data/test/options_test.rb +97 -0
- data/test/reload_test.rb +61 -0
- data/test/request_test.rb +18 -0
- data/test/result_test.rb +88 -0
- data/test/routing_test.rb +391 -0
- data/test/sass_test.rb +27 -48
- data/test/sinatra_test.rb +13 -0
- data/test/static_test.rb +57 -0
- data/test/templates_test.rb +88 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.test +1 -0
- metadata +80 -48
- data/ChangeLog +0 -96
- data/lib/sinatra/test/methods.rb +0 -76
- data/test/event_context_test.rb +0 -15
@@ -0,0 +1,30 @@
|
|
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
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Haml" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Sinatra.application = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
context "without layouts" do
|
10
|
+
|
11
|
+
setup do
|
12
|
+
Sinatra.application = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "should render" do
|
16
|
+
|
17
|
+
get '/no_layout' do
|
18
|
+
haml '== #{1+1}'
|
19
|
+
end
|
20
|
+
|
21
|
+
get_it '/no_layout'
|
22
|
+
should.be.ok
|
23
|
+
body.should == "2\n"
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with layouts" do
|
29
|
+
|
30
|
+
setup do
|
31
|
+
Sinatra.application = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "can be inline" do
|
35
|
+
|
36
|
+
layout do
|
37
|
+
'== This is #{yield}!'
|
38
|
+
end
|
39
|
+
|
40
|
+
get '/lay' do
|
41
|
+
haml 'Blake'
|
42
|
+
end
|
43
|
+
|
44
|
+
get_it '/lay'
|
45
|
+
should.be.ok
|
46
|
+
body.should.equal "This is Blake\n!\n"
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "can use named layouts" do
|
51
|
+
|
52
|
+
layout :pretty do
|
53
|
+
'%h1== #{yield}'
|
54
|
+
end
|
55
|
+
|
56
|
+
get '/pretty' do
|
57
|
+
haml 'Foo', :layout => :pretty
|
58
|
+
end
|
59
|
+
|
60
|
+
get '/not_pretty' do
|
61
|
+
haml 'Bar'
|
62
|
+
end
|
63
|
+
|
64
|
+
get_it '/pretty'
|
65
|
+
body.should.equal "<h1>Foo</h1>\n"
|
66
|
+
|
67
|
+
get_it '/not_pretty'
|
68
|
+
body.should.equal "Bar\n"
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
specify "can be read from a file if they're not inlined" do
|
73
|
+
|
74
|
+
get '/foo' do
|
75
|
+
@title = 'Welcome to the Hello Program'
|
76
|
+
haml 'Blake', :layout => :foo_layout,
|
77
|
+
:views_directory => File.dirname(__FILE__) + "/views"
|
78
|
+
end
|
79
|
+
|
80
|
+
get_it '/foo'
|
81
|
+
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
specify "can be read from file and layout from text" do
|
86
|
+
get '/foo' do
|
87
|
+
haml 'Test', :layout => '== Foo #{yield}'
|
88
|
+
end
|
89
|
+
|
90
|
+
get_it '/foo'
|
91
|
+
|
92
|
+
body.should.equal "Foo Test\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "Templates (in general)" do
|
98
|
+
|
99
|
+
setup do
|
100
|
+
Sinatra.application = nil
|
101
|
+
end
|
102
|
+
|
103
|
+
specify "are read from files if Symbols" do
|
104
|
+
|
105
|
+
get '/from_file' do
|
106
|
+
@name = 'Alena'
|
107
|
+
haml :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
108
|
+
end
|
109
|
+
|
110
|
+
get_it '/from_file'
|
111
|
+
|
112
|
+
body.should.equal "You rock Alena!\n"
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
specify "use layout.ext by default if available" do
|
117
|
+
|
118
|
+
get '/' do
|
119
|
+
haml :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
120
|
+
end
|
121
|
+
|
122
|
+
get_it '/'
|
123
|
+
should.be.ok
|
124
|
+
body.should.equal "x This is foo!\n x\n"
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
specify "renders without layout" do
|
129
|
+
|
130
|
+
get '/' do
|
131
|
+
haml :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
|
132
|
+
end
|
133
|
+
|
134
|
+
get_it '/'
|
135
|
+
should.be.ok
|
136
|
+
body.should.equal "<h1>No Layout!</h1>\n"
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
specify "can render with no layout" do
|
141
|
+
layout do
|
142
|
+
"X\n= yield\nX"
|
143
|
+
end
|
144
|
+
|
145
|
+
get '/' do
|
146
|
+
haml 'blake', :layout => false
|
147
|
+
end
|
148
|
+
|
149
|
+
get_it '/'
|
150
|
+
|
151
|
+
body.should.equal "blake\n"
|
152
|
+
end
|
153
|
+
|
154
|
+
specify "raises error if template not found" do
|
155
|
+
get '/' do
|
156
|
+
haml :not_found
|
157
|
+
end
|
158
|
+
|
159
|
+
lambda { get_it '/' }.should.raise(Errno::ENOENT)
|
160
|
+
end
|
161
|
+
|
162
|
+
specify "use layout.ext by default if available" do
|
163
|
+
|
164
|
+
template :foo do
|
165
|
+
'asdf'
|
166
|
+
end
|
167
|
+
|
168
|
+
get '/' do
|
169
|
+
haml :foo, :layout => false,
|
170
|
+
:views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
171
|
+
end
|
172
|
+
|
173
|
+
get_it '/'
|
174
|
+
should.be.ok
|
175
|
+
body.should.equal "asdf\n"
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'Options passed to the HAML interpreter' do
|
182
|
+
setup do
|
183
|
+
Sinatra.application = nil
|
184
|
+
end
|
185
|
+
|
186
|
+
specify 'are empty be default' do
|
187
|
+
|
188
|
+
get '/' do
|
189
|
+
haml 'foo'
|
190
|
+
end
|
191
|
+
|
192
|
+
Haml::Engine.expects(:new).with('foo', {}).returns(stub(:render => 'foo'))
|
193
|
+
|
194
|
+
get_it '/'
|
195
|
+
should.be.ok
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
specify 'can be configured by passing :options to haml' do
|
200
|
+
|
201
|
+
get '/' do
|
202
|
+
haml 'foo', :options => {:format => :html4}
|
203
|
+
end
|
204
|
+
|
205
|
+
Haml::Engine.expects(:new).with('foo', {:format => :html4}).returns(stub(:render => 'foo'))
|
206
|
+
|
207
|
+
get_it '/'
|
208
|
+
should.be.ok
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
specify 'can be configured using set_option :haml' do
|
213
|
+
|
214
|
+
configure do
|
215
|
+
set_option :haml, :format => :html4,
|
216
|
+
:escape_html => true
|
217
|
+
end
|
218
|
+
|
219
|
+
get '/' do
|
220
|
+
haml 'foo'
|
221
|
+
end
|
222
|
+
|
223
|
+
Haml::Engine.expects(:new).with('foo', {:format => :html4,
|
224
|
+
:escape_html => true}).returns(stub(:render => 'foo'))
|
225
|
+
|
226
|
+
get_it '/'
|
227
|
+
should.be.ok
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
data/compat/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
# disable warnings in compat specs.
|
5
|
+
$VERBOSE = nil
|
6
|
+
|
7
|
+
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
|
8
|
+
|
9
|
+
ENV['RACK_ENV'] ||= 'test'
|
10
|
+
|
11
|
+
require 'sinatra'
|
12
|
+
require 'sinatra/test'
|
13
|
+
require 'sinatra/test/unit'
|
14
|
+
require 'sinatra/test/spec'
|
15
|
+
|
16
|
+
module Sinatra::Test
|
17
|
+
# we need to remove the new test helper methods since they conflict with
|
18
|
+
# the top-level methods of the same name.
|
19
|
+
%w(get head post put delete).each do |verb|
|
20
|
+
remove_method verb
|
21
|
+
end
|
22
|
+
include Sinatra::Delegator
|
23
|
+
end
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
include Sinatra::Test
|
27
|
+
def setup
|
28
|
+
@app = lambda { |env| Sinatra::Application.call(env) }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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
|
@@ -23,24 +23,29 @@ context "Middleware Pipelines" do
|
|
23
23
|
Sinatra.application = nil
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
# Sessions and logging are tested elsewhere. This is a bad test because it
|
27
|
+
# asserts things about the implementation and not the effect.
|
28
|
+
xspecify "includes default middleware with options set" do
|
27
29
|
@app.set_options :sessions => true, :logging => true
|
28
30
|
@app.send(:optional_middleware).should.include([Rack::Session::Cookie, [], nil])
|
29
31
|
@app.send(:optional_middleware).should.include([Rack::CommonLogger, [], nil])
|
30
32
|
end
|
31
33
|
|
32
|
-
|
34
|
+
# Bad test.
|
35
|
+
xspecify "does not include default middleware with options unset" do
|
33
36
|
@app.set_options :sessions => false, :logging => false
|
34
37
|
@app.send(:optional_middleware).should.not.include([Rack::Session::Cookie, [], nil])
|
35
38
|
@app.send(:optional_middleware).should.not.include([Rack::CommonLogger, [], nil])
|
36
39
|
end
|
37
40
|
|
38
|
-
|
41
|
+
# Bad test.
|
42
|
+
xspecify "includes only optional middleware when no explicit middleware added" do
|
39
43
|
@app.set_options :sessions => true, :logging => true
|
40
44
|
@app.send(:middleware).should.equal @app.send(:optional_middleware)
|
41
45
|
end
|
42
46
|
|
43
|
-
|
47
|
+
# Bad test.
|
48
|
+
xspecify "should clear middleware before reload" do
|
44
49
|
@app.clearables.should.include(@app.send(:explicit_middleware))
|
45
50
|
end
|
46
51
|
|
File without changes
|
data/compat/sass_test.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Sass" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Sinatra.application = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Templates (in general)" do
|
10
|
+
|
11
|
+
setup do
|
12
|
+
Sinatra.application = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "are read from files if Symbols" do
|
16
|
+
|
17
|
+
get '/from_file' do
|
18
|
+
sass :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
19
|
+
end
|
20
|
+
|
21
|
+
get_it '/from_file'
|
22
|
+
should.be.ok
|
23
|
+
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "raise an error if template not found" do
|
28
|
+
get '/' do
|
29
|
+
sass :not_found
|
30
|
+
end
|
31
|
+
|
32
|
+
lambda { get_it '/' }.should.raise(Errno::ENOENT)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "ignore default layout file with .sass extension" do
|
36
|
+
get '/' do
|
37
|
+
sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
38
|
+
end
|
39
|
+
|
40
|
+
get_it '/'
|
41
|
+
should.be.ok
|
42
|
+
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "ignore explicitly specified layout file" do
|
46
|
+
get '/' do
|
47
|
+
sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
48
|
+
end
|
49
|
+
|
50
|
+
get_it '/'
|
51
|
+
should.be.ok
|
52
|
+
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|