darkhelmet-sinatra 0.9.1.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/CHANGES +180 -0
- data/LICENSE +1 -1
- data/README.jp.rdoc +552 -0
- data/README.rdoc +177 -38
- data/Rakefile +18 -25
- data/lib/sinatra.rb +1 -2
- data/lib/sinatra/base.rb +405 -305
- data/lib/sinatra/main.rb +5 -24
- data/lib/sinatra/showexceptions.rb +303 -0
- data/lib/sinatra/tilt.rb +509 -0
- data/sinatra.gemspec +21 -51
- data/test/base_test.rb +123 -93
- data/test/builder_test.rb +2 -1
- data/test/contest.rb +64 -0
- data/test/erb_test.rb +1 -1
- data/test/erubis_test.rb +82 -0
- data/test/extensions_test.rb +24 -8
- data/test/filter_test.rb +99 -3
- data/test/haml_test.rb +25 -3
- data/test/helper.rb +43 -48
- data/test/helpers_test.rb +500 -424
- data/test/mapped_error_test.rb +163 -137
- data/test/middleware_test.rb +3 -3
- data/test/request_test.rb +16 -1
- data/test/response_test.rb +2 -2
- data/test/result_test.rb +1 -1
- data/test/route_added_hook_test.rb +59 -0
- data/test/routing_test.rb +170 -22
- data/test/sass_test.rb +44 -1
- data/test/server_test.rb +19 -13
- data/test/sinatra_test.rb +1 -1
- data/test/static_test.rb +9 -2
- data/test/templates_test.rb +78 -11
- data/test/views/error.builder +3 -0
- data/test/views/error.erb +3 -0
- data/test/views/error.erubis +3 -0
- data/test/views/error.haml +3 -0
- data/test/views/error.sass +2 -0
- data/test/views/foo/hello.test +1 -0
- data/test/views/hello.erubis +1 -0
- data/test/views/layout2.erubis +2 -0
- metadata +37 -55
- 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 -233
- data/compat/helper.rb +0 -30
- 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 -57
- data/compat/sessions_test.rb +0 -42
- data/compat/streaming_test.rb +0 -133
- data/compat/sym_params_test.rb +0 -19
- 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 -250
- data/lib/sinatra/test.rb +0 -126
- 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/data/reload_app_file.rb +0 -3
- data/test/options_test.rb +0 -374
- data/test/reload_test.rb +0 -68
- data/test/test_test.rb +0 -144
data/sinatra.gemspec
CHANGED
@@ -2,14 +2,14 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
|
-
s.name = 'sinatra'
|
6
|
-
s.version = '0.
|
7
|
-
s.date = '2009-
|
5
|
+
s.name = 'darkhelmet-sinatra'
|
6
|
+
s.version = '0.10.1'
|
7
|
+
s.date = '2009-12-13'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
11
11
|
|
12
|
-
s.authors = ["Blake Mizerany"]
|
12
|
+
s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet"]
|
13
13
|
s.email = "sinatrarb@googlegroups.com"
|
14
14
|
|
15
15
|
# = MANIFEST =
|
@@ -17,59 +17,22 @@ Gem::Specification.new do |s|
|
|
17
17
|
AUTHORS
|
18
18
|
CHANGES
|
19
19
|
LICENSE
|
20
|
+
README.jp.rdoc
|
20
21
|
README.rdoc
|
21
22
|
Rakefile
|
22
|
-
compat/app_test.rb
|
23
|
-
compat/application_test.rb
|
24
|
-
compat/builder_test.rb
|
25
|
-
compat/compat_test.rb
|
26
|
-
compat/custom_error_test.rb
|
27
|
-
compat/erb_test.rb
|
28
|
-
compat/events_test.rb
|
29
|
-
compat/filter_test.rb
|
30
|
-
compat/haml_test.rb
|
31
|
-
compat/helper.rb
|
32
|
-
compat/mapped_error_test.rb
|
33
|
-
compat/pipeline_test.rb
|
34
|
-
compat/public/foo.xml
|
35
|
-
compat/sass_test.rb
|
36
|
-
compat/sessions_test.rb
|
37
|
-
compat/streaming_test.rb
|
38
|
-
compat/sym_params_test.rb
|
39
|
-
compat/template_test.rb
|
40
|
-
compat/use_in_file_templates_test.rb
|
41
|
-
compat/views/foo.builder
|
42
|
-
compat/views/foo.erb
|
43
|
-
compat/views/foo.haml
|
44
|
-
compat/views/foo.sass
|
45
|
-
compat/views/foo_layout.erb
|
46
|
-
compat/views/foo_layout.haml
|
47
|
-
compat/views/layout_test/foo.builder
|
48
|
-
compat/views/layout_test/foo.erb
|
49
|
-
compat/views/layout_test/foo.haml
|
50
|
-
compat/views/layout_test/foo.sass
|
51
|
-
compat/views/layout_test/layout.builder
|
52
|
-
compat/views/layout_test/layout.erb
|
53
|
-
compat/views/layout_test/layout.haml
|
54
|
-
compat/views/layout_test/layout.sass
|
55
|
-
compat/views/no_layout/no_layout.builder
|
56
|
-
compat/views/no_layout/no_layout.haml
|
57
23
|
lib/sinatra.rb
|
58
24
|
lib/sinatra/base.rb
|
59
|
-
lib/sinatra/compat.rb
|
60
25
|
lib/sinatra/images/404.png
|
61
26
|
lib/sinatra/images/500.png
|
62
27
|
lib/sinatra/main.rb
|
63
|
-
lib/sinatra/
|
64
|
-
lib/sinatra/
|
65
|
-
lib/sinatra/test/rspec.rb
|
66
|
-
lib/sinatra/test/spec.rb
|
67
|
-
lib/sinatra/test/unit.rb
|
28
|
+
lib/sinatra/showexceptions.rb
|
29
|
+
lib/sinatra/tilt.rb
|
68
30
|
sinatra.gemspec
|
69
31
|
test/base_test.rb
|
70
32
|
test/builder_test.rb
|
71
|
-
test/
|
33
|
+
test/contest.rb
|
72
34
|
test/erb_test.rb
|
35
|
+
test/erubis_test.rb
|
73
36
|
test/extensions_test.rb
|
74
37
|
test/filter_test.rb
|
75
38
|
test/haml_test.rb
|
@@ -77,25 +40,31 @@ Gem::Specification.new do |s|
|
|
77
40
|
test/helpers_test.rb
|
78
41
|
test/mapped_error_test.rb
|
79
42
|
test/middleware_test.rb
|
80
|
-
test/options_test.rb
|
81
|
-
test/reload_test.rb
|
82
43
|
test/request_test.rb
|
83
44
|
test/response_test.rb
|
84
45
|
test/result_test.rb
|
46
|
+
test/route_added_hook_test.rb
|
85
47
|
test/routing_test.rb
|
86
48
|
test/sass_test.rb
|
87
49
|
test/server_test.rb
|
88
50
|
test/sinatra_test.rb
|
89
51
|
test/static_test.rb
|
90
52
|
test/templates_test.rb
|
91
|
-
test/
|
53
|
+
test/views/error.builder
|
54
|
+
test/views/error.erb
|
55
|
+
test/views/error.erubis
|
56
|
+
test/views/error.haml
|
57
|
+
test/views/error.sass
|
58
|
+
test/views/foo/hello.test
|
92
59
|
test/views/hello.builder
|
93
60
|
test/views/hello.erb
|
61
|
+
test/views/hello.erubis
|
94
62
|
test/views/hello.haml
|
95
63
|
test/views/hello.sass
|
96
64
|
test/views/hello.test
|
97
65
|
test/views/layout2.builder
|
98
66
|
test/views/layout2.erb
|
67
|
+
test/views/layout2.erubis
|
99
68
|
test/views/layout2.haml
|
100
69
|
test/views/layout2.test
|
101
70
|
]
|
@@ -104,8 +73,9 @@ Gem::Specification.new do |s|
|
|
104
73
|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
105
74
|
|
106
75
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
107
|
-
s.add_dependency 'rack',
|
108
|
-
s.
|
76
|
+
s.add_dependency 'rack', '>= 1.0'
|
77
|
+
s.add_development_dependency 'shotgun', '>= 0.3', '< 1.0'
|
78
|
+
s.add_development_dependency 'rack-test', '>= 0.3.0'
|
109
79
|
|
110
80
|
s.has_rdoc = true
|
111
81
|
s.homepage = "http://sinatra.rubyforge.org"
|
data/test/base_test.rb
CHANGED
@@ -1,130 +1,160 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
def test_default
|
5
|
+
assert true
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
'
|
8
|
+
describe 'Sinatra::Base subclasses' do
|
9
|
+
class TestApp < Sinatra::Base
|
10
|
+
get '/' do
|
11
|
+
'Hello World'
|
12
|
+
end
|
8
13
|
end
|
9
|
-
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
it 'include Rack::Utils' do
|
16
|
+
assert TestApp.included_modules.include?(Rack::Utils)
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
it 'processes requests with #call' do
|
20
|
+
assert TestApp.respond_to?(:call)
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
request = Rack::MockRequest.new(TestApp)
|
23
|
+
response = request.get('/')
|
24
|
+
assert response.ok?
|
25
|
+
assert_equal 'Hello World', response.body
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
class TestApp < Sinatra::Base
|
29
|
+
get '/state' do
|
30
|
+
@foo ||= "new"
|
31
|
+
body = "Foo: #{@foo}"
|
32
|
+
@foo = 'discard'
|
33
|
+
body
|
34
|
+
end
|
29
35
|
end
|
30
|
-
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
it 'does not maintain state between requests' do
|
38
|
+
request = Rack::MockRequest.new(TestApp)
|
39
|
+
2.times do
|
40
|
+
response = request.get('/state')
|
41
|
+
assert response.ok?
|
42
|
+
assert_equal 'Foo: new', response.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "passes the subclass to configure blocks" do
|
47
|
+
ref = nil
|
48
|
+
TestApp.configure { |app| ref = app }
|
49
|
+
assert_equal TestApp, ref
|
50
|
+
end
|
51
|
+
|
52
|
+
it "allows the configure block arg to be omitted and does not change context" do
|
53
|
+
context = nil
|
54
|
+
TestApp.configure { context = self }
|
55
|
+
assert_equal self, context
|
38
56
|
end
|
39
57
|
end
|
40
|
-
end
|
41
58
|
|
42
|
-
describe "Sinatra::Base as Rack middleware" do
|
59
|
+
describe "Sinatra::Base as Rack middleware" do
|
60
|
+
app = lambda { |env|
|
61
|
+
headers = {'X-Downstream' => 'true'}
|
62
|
+
headers['X-Route-Missing'] = env['sinatra.route-missing'] || ''
|
63
|
+
[210, headers, ['Hello from downstream']] }
|
43
64
|
|
44
|
-
|
45
|
-
|
65
|
+
class TestMiddleware < Sinatra::Base
|
66
|
+
end
|
46
67
|
|
47
|
-
|
48
|
-
|
68
|
+
it 'creates a middleware that responds to #call with .new' do
|
69
|
+
middleware = TestMiddleware.new(app)
|
70
|
+
assert middleware.respond_to?(:call)
|
71
|
+
end
|
49
72
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
73
|
+
it 'exposes the downstream app' do
|
74
|
+
middleware = TestMiddleware.new(app)
|
75
|
+
assert_same app, middleware.app
|
76
|
+
end
|
77
|
+
|
78
|
+
class TestMiddleware < Sinatra::Base
|
79
|
+
def route_missing
|
80
|
+
env['sinatra.route-missing'] = '1'
|
81
|
+
super
|
82
|
+
end
|
83
|
+
|
84
|
+
get '/' do
|
85
|
+
'Hello from middleware'
|
86
|
+
end
|
87
|
+
end
|
54
88
|
|
55
|
-
it 'exposes the downstream app' do
|
56
89
|
middleware = TestMiddleware.new(app)
|
57
|
-
|
58
|
-
end
|
90
|
+
request = Rack::MockRequest.new(middleware)
|
59
91
|
|
60
|
-
|
61
|
-
|
62
|
-
|
92
|
+
it 'intercepts requests' do
|
93
|
+
response = request.get('/')
|
94
|
+
assert response.ok?
|
95
|
+
assert_equal 'Hello from middleware', response.body
|
63
96
|
end
|
64
|
-
end
|
65
97
|
|
66
|
-
|
67
|
-
|
98
|
+
it 'automatically forwards requests downstream when no matching route found' do
|
99
|
+
response = request.get('/missing')
|
100
|
+
assert_equal 210, response.status
|
101
|
+
assert_equal 'Hello from downstream', response.body
|
102
|
+
end
|
68
103
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
104
|
+
it 'calls #route_missing before forwarding downstream' do
|
105
|
+
response = request.get('/missing')
|
106
|
+
assert_equal '1', response['X-Route-Missing']
|
107
|
+
end
|
74
108
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
109
|
+
class TestMiddleware < Sinatra::Base
|
110
|
+
get '/low-level-forward' do
|
111
|
+
app.call(env)
|
112
|
+
end
|
113
|
+
end
|
80
114
|
|
81
|
-
|
82
|
-
|
83
|
-
|
115
|
+
it 'can call the downstream app directly and return result' do
|
116
|
+
response = request.get('/low-level-forward')
|
117
|
+
assert_equal 210, response.status
|
118
|
+
assert_equal 'true', response['X-Downstream']
|
119
|
+
assert_equal 'Hello from downstream', response.body
|
84
120
|
end
|
85
|
-
end
|
86
121
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
122
|
+
class TestMiddleware < Sinatra::Base
|
123
|
+
get '/explicit-forward' do
|
124
|
+
response['X-Middleware'] = 'true'
|
125
|
+
res = forward
|
126
|
+
assert_nil res
|
127
|
+
assert_equal 210, response.status
|
128
|
+
assert_equal 'true', response['X-Downstream']
|
129
|
+
assert_equal ['Hello from downstream'], response.body
|
130
|
+
'Hello after explicit forward'
|
131
|
+
end
|
132
|
+
end
|
93
133
|
|
94
|
-
|
95
|
-
|
96
|
-
response['X-Middleware'] = 'true'
|
97
|
-
res = forward
|
98
|
-
assert_nil res
|
134
|
+
it 'forwards the request downstream and integrates the response into the current context' do
|
135
|
+
response = request.get('/explicit-forward')
|
99
136
|
assert_equal 210, response.status
|
100
137
|
assert_equal 'true', response['X-Downstream']
|
101
|
-
assert_equal
|
102
|
-
'
|
138
|
+
assert_equal 'Hello after explicit forward', response.body
|
139
|
+
assert_equal '28', response['Content-Length']
|
103
140
|
end
|
104
|
-
end
|
105
141
|
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal 210, response.status
|
109
|
-
assert_equal 'true', response['X-Downstream']
|
110
|
-
assert_equal 'Hello after explicit forward', response.body
|
111
|
-
assert_equal '28', response['Content-Length']
|
112
|
-
end
|
142
|
+
app_content_length = lambda {|env|
|
143
|
+
[200, {'Content-Length' => '16'}, 'From downstream!']}
|
113
144
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
'From after explicit forward!'
|
145
|
+
class TestMiddlewareContentLength < Sinatra::Base
|
146
|
+
get '/forward' do
|
147
|
+
res = forward
|
148
|
+
'From after explicit forward!'
|
149
|
+
end
|
120
150
|
end
|
121
|
-
end
|
122
151
|
|
123
|
-
|
124
|
-
|
152
|
+
middleware_content_length = TestMiddlewareContentLength.new(app_content_length)
|
153
|
+
request_content_length = Rack::MockRequest.new(middleware_content_length)
|
125
154
|
|
126
|
-
|
127
|
-
|
128
|
-
|
155
|
+
it "sets content length for last response" do
|
156
|
+
response = request_content_length.get('/forward')
|
157
|
+
assert_equal '28', response['Content-Length']
|
158
|
+
end
|
129
159
|
end
|
130
160
|
end
|
data/test/builder_test.rb
CHANGED
data/test/contest.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
# Test::Unit loads a default test if the suite is empty, and the only
|
4
|
+
# purpose of that test is to fail. As having empty contexts is a common
|
5
|
+
# practice, we decided to overwrite TestSuite#empty? in order to
|
6
|
+
# allow them. Having a failure when no tests have been defined seems
|
7
|
+
# counter-intuitive.
|
8
|
+
class Test::Unit::TestSuite
|
9
|
+
unless method_defined?(:empty?)
|
10
|
+
def empty?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# We added setup, test and context as class methods, and the instance
|
17
|
+
# method setup now iterates on the setup blocks. Note that all setup
|
18
|
+
# blocks must be defined with the block syntax. Adding a setup instance
|
19
|
+
# method defeats the purpose of this library.
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
def self.setup(&block)
|
22
|
+
setup_blocks << block
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
self.class.setup_blocks.each do |block|
|
27
|
+
instance_eval(&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.context(name, &block)
|
32
|
+
subclass = Class.new(self.superclass)
|
33
|
+
subclass.setup_blocks.unshift(*setup_blocks)
|
34
|
+
subclass.class_eval(&block)
|
35
|
+
const_set(context_name(name), subclass)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.test(name, &block)
|
39
|
+
define_method(test_name(name), &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
alias_method :should, :test
|
44
|
+
alias_method :describe, :context
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.setup_blocks
|
50
|
+
@setup_blocks ||= []
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.context_name(name)
|
54
|
+
"Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.test_name(name)
|
58
|
+
"test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.sanitize_name(name)
|
62
|
+
name.gsub(/\W+/, ' ').strip
|
63
|
+
end
|
64
|
+
end
|