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
@@ -1,145 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
require 'sass/error'
|
4
|
-
|
5
|
-
class RenderBacktraceTest < Test::Unit::TestCase
|
6
|
-
VIEWS = File.dirname(__FILE__) + '/views'
|
7
|
-
|
8
|
-
def assert_raise_at(filename, line, exception = RuntimeError)
|
9
|
-
f, l = nil
|
10
|
-
assert_raise(exception) do
|
11
|
-
begin
|
12
|
-
get('/')
|
13
|
-
rescue => e
|
14
|
-
f, l = e.backtrace.first.split(':')
|
15
|
-
raise
|
16
|
-
end
|
17
|
-
end
|
18
|
-
assert_equal(filename, f, "expected #{exception.name} in #{filename}, was #{f}")
|
19
|
-
assert_equal(line, l.to_i, "expected #{exception.name} in #{filename} at line #{line}, was at line #{l}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def backtrace_app(&block)
|
23
|
-
mock_app {
|
24
|
-
enable :inline_templates
|
25
|
-
set :views, RenderBacktraceTest::VIEWS
|
26
|
-
template :builder_template do
|
27
|
-
'raise "error"'
|
28
|
-
end
|
29
|
-
template :erb_template do
|
30
|
-
'<% raise "error" %>'
|
31
|
-
end
|
32
|
-
template :haml_template do
|
33
|
-
'%h1= raise "error"'
|
34
|
-
end
|
35
|
-
template :sass_template do
|
36
|
-
'+syntax-error'
|
37
|
-
end
|
38
|
-
get '/', &block
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "provides backtrace for Builder template" do
|
43
|
-
backtrace_app { builder :error }
|
44
|
-
assert_raise_at(File.join(VIEWS,'error.builder'), 2)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "provides backtrace for ERB template" do
|
48
|
-
backtrace_app { erb :error }
|
49
|
-
assert_raise_at(File.join(VIEWS,'error.erb'), 2)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "provides backtrace for HAML template" do
|
53
|
-
backtrace_app { haml :error }
|
54
|
-
assert_raise_at(File.join(VIEWS,'error.haml'), 2)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "provides backtrace for Sass template" do
|
58
|
-
backtrace_app { sass :error }
|
59
|
-
assert_raise_at(File.join(VIEWS,'error.sass'), 2, Sass::SyntaxError)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "provides backtrace for ERB template with locals" do
|
63
|
-
backtrace_app { erb :error, {}, :french => true }
|
64
|
-
assert_raise_at(File.join(VIEWS,'error.erb'), 3)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "provides backtrace for HAML template with locals" do
|
68
|
-
backtrace_app { haml :error, {}, :french => true }
|
69
|
-
assert_raise_at(File.join(VIEWS,'error.haml'), 3)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "provides backtrace for inline Builder string" do
|
73
|
-
backtrace_app { builder "raise 'Ack! Thbbbt!'"}
|
74
|
-
assert_raise_at(__FILE__, (__LINE__-1))
|
75
|
-
end
|
76
|
-
|
77
|
-
it "provides backtrace for inline ERB string" do
|
78
|
-
backtrace_app { erb "<% raise 'bidi-bidi-bidi' %>" }
|
79
|
-
assert_raise_at(__FILE__, (__LINE__-1))
|
80
|
-
end
|
81
|
-
|
82
|
-
it "provides backtrace for inline HAML string" do
|
83
|
-
backtrace_app { haml "%h1= raise 'Lions and tigers and bears! Oh, my!'" }
|
84
|
-
assert_raise_at(__FILE__, (__LINE__-1))
|
85
|
-
end
|
86
|
-
|
87
|
-
# it "provides backtrace for inline Sass string" do
|
88
|
-
# backtrace_app { sass '+buh-bye' }
|
89
|
-
# assert_raise_at(__FILE__, (__LINE__-1), Sass::SyntaxError)
|
90
|
-
# end
|
91
|
-
|
92
|
-
it "provides backtrace for named Builder template" do
|
93
|
-
backtrace_app { builder :builder_template }
|
94
|
-
assert_raise_at(__FILE__, (__LINE__-68))
|
95
|
-
end
|
96
|
-
|
97
|
-
it "provides backtrace for named ERB template" do
|
98
|
-
backtrace_app { erb :erb_template }
|
99
|
-
assert_raise_at(__FILE__, (__LINE__-70))
|
100
|
-
end
|
101
|
-
|
102
|
-
it "provides backtrace for named HAML template" do
|
103
|
-
backtrace_app { haml :haml_template }
|
104
|
-
assert_raise_at(__FILE__, (__LINE__-72))
|
105
|
-
end
|
106
|
-
|
107
|
-
# it "provides backtrace for named Sass template" do
|
108
|
-
# backtrace_app { sass :sass_template }
|
109
|
-
# assert_raise_at(__FILE__, (__LINE__-74), Sass::SyntaxError)
|
110
|
-
# end
|
111
|
-
|
112
|
-
it "provides backtrace for in file Builder template" do
|
113
|
-
backtrace_app { builder :builder_in_file }
|
114
|
-
assert_raise_at(__FILE__, (__LINE__+22))
|
115
|
-
end
|
116
|
-
|
117
|
-
it "provides backtrace for in file ERB template" do
|
118
|
-
backtrace_app { erb :erb_in_file }
|
119
|
-
assert_raise_at(__FILE__, (__LINE__+20))
|
120
|
-
end
|
121
|
-
|
122
|
-
it "provides backtrace for in file HAML template" do
|
123
|
-
backtrace_app { haml :haml_in_file }
|
124
|
-
assert_raise_at(__FILE__, (__LINE__+18))
|
125
|
-
end
|
126
|
-
|
127
|
-
# it "provides backtrace for in file Sass template" do
|
128
|
-
# backtrace_app { sass :sass_in_file }
|
129
|
-
# assert_raise_at(__FILE__, (__LINE__+16), Sass::SyntaxError)
|
130
|
-
# end
|
131
|
-
end
|
132
|
-
|
133
|
-
__END__
|
134
|
-
|
135
|
-
@@ builder_in_file
|
136
|
-
raise "bif"
|
137
|
-
|
138
|
-
@@ erb_in_file
|
139
|
-
<% raise "bam" %>
|
140
|
-
|
141
|
-
@@ haml_in_file
|
142
|
-
%h1= raise "pow"
|
143
|
-
|
144
|
-
@@ sass_in_file
|
145
|
-
+blam
|
data/test/test_test.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
# silence deprecation warning when requiring sinatra/test
|
6
|
-
$VERBOSE, v = nil, $VERBOSE
|
7
|
-
require 'sinatra/test'
|
8
|
-
$VERBOSE = v
|
9
|
-
|
10
|
-
class TestTest < Test::Unit::TestCase
|
11
|
-
include Sinatra::Test
|
12
|
-
|
13
|
-
def request
|
14
|
-
YAML.load(body)
|
15
|
-
end
|
16
|
-
|
17
|
-
def request_body
|
18
|
-
request['test.body']
|
19
|
-
end
|
20
|
-
|
21
|
-
def request_params
|
22
|
-
YAML.load(request['test.params'])
|
23
|
-
end
|
24
|
-
|
25
|
-
setup do
|
26
|
-
mock_app {
|
27
|
-
%w[get head post put delete].each { |verb|
|
28
|
-
send(verb, '/') do
|
29
|
-
redirect '/redirected' if params[:redirect]
|
30
|
-
env.update('test.body' => request.body.read)
|
31
|
-
env.update('test.params' => params.to_yaml)
|
32
|
-
env.to_yaml
|
33
|
-
end
|
34
|
-
}
|
35
|
-
|
36
|
-
get '/redirected' do
|
37
|
-
"you've been redirected"
|
38
|
-
end
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'allows GET/HEAD/POST/PUT/DELETE' do
|
43
|
-
get '/'
|
44
|
-
assert_equal('GET', request['REQUEST_METHOD'])
|
45
|
-
|
46
|
-
post '/'
|
47
|
-
assert_equal('POST', request['REQUEST_METHOD'])
|
48
|
-
|
49
|
-
put '/'
|
50
|
-
assert_equal('PUT', request['REQUEST_METHOD'])
|
51
|
-
|
52
|
-
delete '/'
|
53
|
-
assert_equal('DELETE', request['REQUEST_METHOD'])
|
54
|
-
|
55
|
-
head '/'
|
56
|
-
assert response.headers['Content-Length'].to_i > 0
|
57
|
-
assert_equal('', body)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'allows to specify a body' do
|
61
|
-
post '/', '42'
|
62
|
-
assert_equal '42', request_body
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'allows to specify params' do
|
66
|
-
get '/', :foo => 'bar'
|
67
|
-
assert_equal 'bar', request_params['foo']
|
68
|
-
|
69
|
-
post '/', :foo => 'bar'
|
70
|
-
assert_equal 'bar', request_params['foo']
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'supports nested params' do
|
74
|
-
get '/', :foo => { :x => 'y', :chunky => 'bacon' }
|
75
|
-
assert_equal "y", request_params['foo']['x']
|
76
|
-
assert_equal "bacon", request_params['foo']['chunky']
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'provides easy access to response status and body' do
|
80
|
-
get '/'
|
81
|
-
assert_equal 200, status
|
82
|
-
assert body =~ /^---/
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'delegates methods to @response' do
|
86
|
-
get '/'
|
87
|
-
assert ok?
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'follows redirect' do
|
91
|
-
get '/', :redirect => true
|
92
|
-
follow!
|
93
|
-
assert_equal "you've been redirected", body
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'provides sugar for common HTTP headers' do
|
97
|
-
get '/', :env => { :accept => 'text/plain' }
|
98
|
-
assert_equal 'text/plain', request['HTTP_ACCEPT']
|
99
|
-
|
100
|
-
get '/', :env => { :agent => 'TATFT' }
|
101
|
-
assert_equal 'TATFT', request['HTTP_USER_AGENT']
|
102
|
-
|
103
|
-
get '/', :env => { :host => '1.2.3.4' }
|
104
|
-
assert_equal '1.2.3.4', request['HTTP_HOST']
|
105
|
-
|
106
|
-
get '/', :env => { :session => {'foo' => 'bar'} }
|
107
|
-
assert_equal({'foo' => 'bar'}, request['rack.session'])
|
108
|
-
|
109
|
-
get '/', :env => { :cookies => 'foo' }
|
110
|
-
assert_equal 'foo', request['HTTP_COOKIE']
|
111
|
-
|
112
|
-
get '/', :env => { :content_type => 'text/plain' }
|
113
|
-
assert_equal 'text/plain', request['CONTENT_TYPE']
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'allow to test session easily' do
|
117
|
-
app = mock_app(Sinatra::Base) {
|
118
|
-
get '/' do
|
119
|
-
session['foo'] = 'bar'
|
120
|
-
200
|
121
|
-
end
|
122
|
-
|
123
|
-
post '/' do
|
124
|
-
assert_equal 'bar', session['foo']
|
125
|
-
session['foo'] || "blah"
|
126
|
-
end
|
127
|
-
}
|
128
|
-
|
129
|
-
browser = Sinatra::TestHarness.new(app)
|
130
|
-
browser.get '/'
|
131
|
-
browser.post '/', {}, :session => { 'foo' => 'bar' }
|
132
|
-
assert_equal 'bar', browser.response.body
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'yields the request object to the block before invoking the application' do
|
136
|
-
called = false
|
137
|
-
get '/' do |req|
|
138
|
-
called = true
|
139
|
-
assert req.kind_of?(Rack::MockRequest)
|
140
|
-
end
|
141
|
-
assert called
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'sets the environment to :test on include' do
|
145
|
-
Sinatra::Application.set(:environment, :production)
|
146
|
-
Class.new { include Sinatra::Test }
|
147
|
-
assert_equal :test, Sinatra::Application.environment
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_TestHarness
|
151
|
-
session = Sinatra::TestHarness.new(@app)
|
152
|
-
response = session.get('/')
|
153
|
-
assert_equal 200, response.status
|
154
|
-
end
|
155
|
-
end
|