sinatra 1.4.8 → 2.0.0.beta1

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.

Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -47
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +37 -49
  5. data/MAINTENANCE.md +42 -0
  6. data/README.de.md +5 -5
  7. data/README.es.md +5 -5
  8. data/README.fr.md +9 -9
  9. data/README.hu.md +3 -3
  10. data/README.ja.md +19 -8
  11. data/README.ko.md +8 -8
  12. data/README.md +90 -61
  13. data/README.pt-br.md +3 -3
  14. data/README.pt-pt.md +2 -2
  15. data/README.ru.md +42 -26
  16. data/README.zh.md +8 -8
  17. data/Rakefile +0 -6
  18. data/SECURITY.md +35 -0
  19. data/lib/sinatra/base.rb +113 -161
  20. data/lib/sinatra/main.rb +1 -0
  21. data/lib/sinatra/show_exceptions.rb +8 -8
  22. data/lib/sinatra/version.rb +1 -1
  23. data/sinatra.gemspec +7 -4
  24. metadata +34 -168
  25. data/lib/sinatra/ext.rb +0 -17
  26. data/test/asciidoctor_test.rb +0 -72
  27. data/test/base_test.rb +0 -167
  28. data/test/builder_test.rb +0 -91
  29. data/test/coffee_test.rb +0 -96
  30. data/test/compile_test.rb +0 -183
  31. data/test/contest.rb +0 -91
  32. data/test/creole_test.rb +0 -65
  33. data/test/delegator_test.rb +0 -160
  34. data/test/encoding_test.rb +0 -20
  35. data/test/erb_test.rb +0 -116
  36. data/test/extensions_test.rb +0 -98
  37. data/test/filter_test.rb +0 -487
  38. data/test/haml_test.rb +0 -109
  39. data/test/helper.rb +0 -132
  40. data/test/helpers_test.rb +0 -1917
  41. data/test/integration/app.rb +0 -79
  42. data/test/integration_helper.rb +0 -236
  43. data/test/integration_test.rb +0 -104
  44. data/test/less_test.rb +0 -69
  45. data/test/liquid_test.rb +0 -77
  46. data/test/mapped_error_test.rb +0 -285
  47. data/test/markaby_test.rb +0 -80
  48. data/test/markdown_test.rb +0 -85
  49. data/test/mediawiki_test.rb +0 -68
  50. data/test/middleware_test.rb +0 -68
  51. data/test/nokogiri_test.rb +0 -67
  52. data/test/public/favicon.ico +0 -0
  53. data/test/public/hello+world.txt +0 -1
  54. data/test/rabl_test.rb +0 -89
  55. data/test/rack_test.rb +0 -45
  56. data/test/radius_test.rb +0 -59
  57. data/test/rdoc_test.rb +0 -66
  58. data/test/readme_test.rb +0 -130
  59. data/test/request_test.rb +0 -100
  60. data/test/response_test.rb +0 -63
  61. data/test/result_test.rb +0 -76
  62. data/test/route_added_hook_test.rb +0 -59
  63. data/test/routing_test.rb +0 -1456
  64. data/test/sass_test.rb +0 -115
  65. data/test/scss_test.rb +0 -88
  66. data/test/server_test.rb +0 -56
  67. data/test/settings_test.rb +0 -582
  68. data/test/sinatra_test.rb +0 -12
  69. data/test/slim_test.rb +0 -102
  70. data/test/static_test.rb +0 -266
  71. data/test/streaming_test.rb +0 -149
  72. data/test/stylus_test.rb +0 -90
  73. data/test/templates_test.rb +0 -382
  74. data/test/textile_test.rb +0 -65
  75. data/test/views/a/in_a.str +0 -1
  76. data/test/views/ascii.erb +0 -2
  77. data/test/views/b/in_b.str +0 -1
  78. data/test/views/calc.html.erb +0 -1
  79. data/test/views/error.builder +0 -3
  80. data/test/views/error.erb +0 -3
  81. data/test/views/error.haml +0 -3
  82. data/test/views/error.sass +0 -2
  83. data/test/views/explicitly_nested.str +0 -1
  84. data/test/views/foo/hello.test +0 -1
  85. data/test/views/hello.asciidoc +0 -1
  86. data/test/views/hello.builder +0 -1
  87. data/test/views/hello.coffee +0 -1
  88. data/test/views/hello.creole +0 -1
  89. data/test/views/hello.erb +0 -1
  90. data/test/views/hello.haml +0 -1
  91. data/test/views/hello.less +0 -5
  92. data/test/views/hello.liquid +0 -1
  93. data/test/views/hello.mab +0 -1
  94. data/test/views/hello.md +0 -1
  95. data/test/views/hello.mediawiki +0 -1
  96. data/test/views/hello.nokogiri +0 -1
  97. data/test/views/hello.rabl +0 -2
  98. data/test/views/hello.radius +0 -1
  99. data/test/views/hello.rdoc +0 -1
  100. data/test/views/hello.sass +0 -2
  101. data/test/views/hello.scss +0 -3
  102. data/test/views/hello.slim +0 -1
  103. data/test/views/hello.str +0 -1
  104. data/test/views/hello.styl +0 -2
  105. data/test/views/hello.test +0 -1
  106. data/test/views/hello.textile +0 -1
  107. data/test/views/hello.wlang +0 -1
  108. data/test/views/hello.yajl +0 -1
  109. data/test/views/layout2.builder +0 -3
  110. data/test/views/layout2.erb +0 -2
  111. data/test/views/layout2.haml +0 -2
  112. data/test/views/layout2.liquid +0 -2
  113. data/test/views/layout2.mab +0 -2
  114. data/test/views/layout2.nokogiri +0 -3
  115. data/test/views/layout2.rabl +0 -3
  116. data/test/views/layout2.radius +0 -2
  117. data/test/views/layout2.slim +0 -3
  118. data/test/views/layout2.str +0 -2
  119. data/test/views/layout2.test +0 -1
  120. data/test/views/layout2.wlang +0 -2
  121. data/test/views/nested.str +0 -1
  122. data/test/views/utf8.erb +0 -2
  123. data/test/wlang_test.rb +0 -87
  124. data/test/yajl_test.rb +0 -86
@@ -1,77 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'liquid'
5
-
6
- class LiquidTest < Minitest::Test
7
- def liquid_app(&block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- get('/', &block)
11
- end
12
- get '/'
13
- end
14
-
15
- it 'renders inline liquid strings' do
16
- liquid_app { liquid '<h1>Hiya</h1>' }
17
- assert ok?
18
- assert_equal "<h1>Hiya</h1>", body
19
- end
20
-
21
- it 'renders .liquid files in views path' do
22
- liquid_app { liquid :hello }
23
- assert ok?
24
- assert_equal "<h1>Hello From Liquid</h1>\n", body
25
- end
26
-
27
- it "renders with inline layouts" do
28
- mock_app do
29
- layout { "<h1>THIS. IS. {{ yield }}</h1>" }
30
- get('/') { liquid '<EM>SPARTA</EM>' }
31
- end
32
- get '/'
33
- assert ok?
34
- assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
35
- end
36
-
37
- it "renders with file layouts" do
38
- liquid_app { liquid 'Hello World', :layout => :layout2 }
39
- assert ok?
40
- assert_equal "<h1>Liquid Layout!</h1>\n<p>Hello World</p>\n", body
41
- end
42
-
43
- it "raises error if template not found" do
44
- mock_app { get('/') { liquid :no_such_template } }
45
- assert_raises(Errno::ENOENT) { get('/') }
46
- end
47
-
48
- it "allows passing locals" do
49
- liquid_app {
50
- liquid '{{ value }}', :locals => { :value => 'foo' }
51
- }
52
- assert ok?
53
- assert_equal 'foo', body
54
- end
55
-
56
- it "can render truly nested layouts by accepting a layout and a block with the contents" do
57
- mock_app do
58
- template(:main_outer_layout) { "<h1>Title</h1>\n{{ yield }}" }
59
- template(:an_inner_layout) { "<h2>Subtitle</h2>\n{{ yield }}" }
60
- template(:a_page) { "<p>Contents.</p>\n" }
61
- get('/') do
62
- liquid :main_outer_layout, :layout => false do
63
- liquid :an_inner_layout do
64
- liquid :a_page
65
- end
66
- end
67
- end
68
- end
69
- get '/'
70
- assert ok?
71
- assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
72
- end
73
- end
74
-
75
- rescue LoadError
76
- warn "#{$!.to_s}: skipping liquid tests"
77
- end
@@ -1,285 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class FooError < RuntimeError
4
- end
5
-
6
- class FooNotFound < Sinatra::NotFound
7
- end
8
-
9
- class FooSpecialError < RuntimeError
10
- def http_status; 501 end
11
- end
12
-
13
- class FooStatusOutOfRangeError < RuntimeError
14
- def code; 4000 end
15
- end
16
-
17
- class FooWithCode < RuntimeError
18
- def code; 419 end
19
- end
20
-
21
- class FirstError < RuntimeError; end
22
- class SecondError < RuntimeError; end
23
-
24
- class MappedErrorTest < Minitest::Test
25
- def test_default
26
- assert true
27
- end
28
-
29
- describe 'Exception Mappings' do
30
- it 'invokes handlers registered with ::error when raised' do
31
- mock_app do
32
- set :raise_errors, false
33
- error(FooError) { 'Foo!' }
34
- get('/') { raise FooError }
35
- end
36
- get '/'
37
- assert_equal 500, status
38
- assert_equal 'Foo!', body
39
- end
40
-
41
- it 'passes the exception object to the error handler' do
42
- mock_app do
43
- set :raise_errors, false
44
- error(FooError) { |e| assert_equal(FooError, e.class) }
45
- get('/') { raise FooError }
46
- end
47
- get('/')
48
- end
49
-
50
- it 'uses the Exception handler if no matching handler found' do
51
- mock_app do
52
- set :raise_errors, false
53
- error(Exception) { 'Exception!' }
54
- get('/') { raise FooError }
55
- end
56
-
57
- get '/'
58
- assert_equal 500, status
59
- assert_equal 'Exception!', body
60
- end
61
-
62
- it 'walks down inheritance chain for errors' do
63
- mock_app do
64
- set :raise_errors, false
65
- error(RuntimeError) { 'Exception!' }
66
- get('/') { raise FooError }
67
- end
68
-
69
- get '/'
70
- assert_equal 500, status
71
- assert_equal 'Exception!', body
72
- end
73
-
74
- it 'favors subclass handler over superclass handler if available' do
75
- mock_app do
76
- set :raise_errors, false
77
- error(Exception) { 'Exception!' }
78
- error(FooError) { 'FooError!' }
79
- error(RuntimeError) { 'Exception!' }
80
- get('/') { raise FooError }
81
- end
82
-
83
- get '/'
84
- assert_equal 500, status
85
- assert_equal 'FooError!', body
86
- end
87
-
88
- it "sets env['sinatra.error'] to the rescued exception" do
89
- mock_app do
90
- set :raise_errors, false
91
- error(FooError) do
92
- assert env.include?('sinatra.error')
93
- assert env['sinatra.error'].kind_of?(FooError)
94
- 'looks good'
95
- end
96
- get('/') { raise FooError }
97
- end
98
- get '/'
99
- assert_equal 'looks good', body
100
- end
101
-
102
- it "raises errors from the app when raise_errors set and no handler defined" do
103
- mock_app do
104
- set :raise_errors, true
105
- get('/') { raise FooError }
106
- end
107
- assert_raises(FooError) { get '/' }
108
- end
109
-
110
- it "calls error handlers before raising errors even when raise_errors is set" do
111
- mock_app do
112
- set :raise_errors, true
113
- error(FooError) { "she's there." }
114
- get('/') { raise FooError }
115
- end
116
- get '/'
117
- assert_equal 500, status
118
- end
119
-
120
- it "never raises Sinatra::NotFound beyond the application" do
121
- mock_app(Sinatra::Application) do
122
- get('/') { raise Sinatra::NotFound }
123
- end
124
- get '/'
125
- assert_equal 404, status
126
- end
127
-
128
- it "cascades for subclasses of Sinatra::NotFound" do
129
- mock_app do
130
- set :raise_errors, true
131
- error(FooNotFound) { "foo! not found." }
132
- get('/') { raise FooNotFound }
133
- end
134
- get '/'
135
- assert_equal 404, status
136
- assert_equal 'foo! not found.', body
137
- end
138
-
139
- it 'has a not_found method for backwards compatibility' do
140
- mock_app { not_found { "Lost, are we?" } }
141
-
142
- get '/test'
143
- assert_equal 404, status
144
- assert_equal "Lost, are we?", body
145
- end
146
-
147
- it 'inherits error mappings from base class' do
148
- base = Class.new(Sinatra::Base)
149
- base.error(FooError) { 'base class' }
150
-
151
- mock_app(base) do
152
- set :raise_errors, false
153
- get('/') { raise FooError }
154
- end
155
-
156
- get '/'
157
- assert_equal 'base class', body
158
- end
159
-
160
- it 'overrides error mappings in base class' do
161
- base = Class.new(Sinatra::Base)
162
- base.error(FooError) { 'base class' }
163
-
164
- mock_app(base) do
165
- set :raise_errors, false
166
- error(FooError) { 'subclass' }
167
- get('/') { raise FooError }
168
- end
169
-
170
- get '/'
171
- assert_equal 'subclass', body
172
- end
173
-
174
- it 'honors Exception#http_status if present' do
175
- mock_app do
176
- set :raise_errors, false
177
- error(501) { 'Foo!' }
178
- get('/') { raise FooSpecialError }
179
- end
180
- get '/'
181
- assert_equal 501, status
182
- assert_equal 'Foo!', body
183
- end
184
-
185
- it 'does not use Exception#code by default' do
186
- mock_app do
187
- set :raise_errors, false
188
- get('/') { raise FooWithCode }
189
- end
190
- get '/'
191
- assert_equal 500, status
192
- end
193
-
194
- it 'uses Exception#code if use_code is enabled' do
195
- mock_app do
196
- set :raise_errors, false
197
- set :use_code, true
198
- get('/') { raise FooWithCode }
199
- end
200
- get '/'
201
- assert_equal 419, status
202
- end
203
-
204
- it 'does not rely on Exception#code for invalid codes' do
205
- mock_app do
206
- set :raise_errors, false
207
- set :use_code, true
208
- get('/') { raise FooStatusOutOfRangeError }
209
- end
210
- get '/'
211
- assert_equal 500, status
212
- end
213
-
214
- it "allows a stack of exception_handlers" do
215
- mock_app do
216
- set :raise_errors, false
217
- error(FirstError) { 'First!' }
218
- error(SecondError) { 'Second!' }
219
- get('/'){ raise SecondError }
220
- end
221
- get '/'
222
- assert_equal 500, status
223
- assert_equal 'Second!', body
224
- end
225
-
226
- it "allows an exception handler to pass control to the next exception handler" do
227
- mock_app do
228
- set :raise_errors, false
229
- error(500, FirstError) { 'First!' }
230
- error(500, SecondError) { pass }
231
- get('/') { raise 500 }
232
- end
233
- get '/'
234
- assert_equal 500, status
235
- assert_equal 'First!', body
236
- end
237
-
238
- it "allows an exception handler to handle the exception" do
239
- mock_app do
240
- set :raise_errors, false
241
- error(500, FirstError) { 'First!' }
242
- error(500, SecondError) { 'Second!' }
243
- get('/') { raise 500 }
244
- end
245
- get '/'
246
- assert_equal 500, status
247
- assert_equal 'Second!', body
248
- end
249
- end
250
-
251
- describe 'Custom Error Pages' do
252
- it 'allows numeric status code mappings to be registered with ::error' do
253
- mock_app do
254
- set :raise_errors, false
255
- error(500) { 'Foo!' }
256
- get('/') { [500, {}, 'Internal Foo Error'] }
257
- end
258
- get '/'
259
- assert_equal 500, status
260
- assert_equal 'Foo!', body
261
- end
262
-
263
- it 'allows ranges of status code mappings to be registered with :error' do
264
- mock_app do
265
- set :raise_errors, false
266
- error(500..550) { "Error: #{response.status}" }
267
- get('/') { [507, {}, 'A very special error'] }
268
- end
269
- get '/'
270
- assert_equal 507, status
271
- assert_equal 'Error: 507', body
272
- end
273
-
274
- it 'allows passing more than one range' do
275
- mock_app do
276
- set :raise_errors, false
277
- error(409..411, 503..509) { "Error: #{response.status}" }
278
- get('/') { [507, {}, 'A very special error'] }
279
- end
280
- get '/'
281
- assert_equal 507, status
282
- assert_equal 'Error: 507', body
283
- end
284
- end
285
- end
@@ -1,80 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'markaby'
5
-
6
- class MarkabyTest < Minitest::Test
7
- def markaby_app(&block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- get('/', &block)
11
- end
12
- get '/'
13
- end
14
-
15
- it 'renders inline markaby strings' do
16
- markaby_app { markaby 'h1 "Hiya"' }
17
- assert ok?
18
- assert_equal "<h1>Hiya</h1>", body
19
- end
20
-
21
- it 'renders .markaby files in views path' do
22
- markaby_app { markaby :hello }
23
- assert ok?
24
- assert_equal "<h1>Hello From Markaby</h1>", body
25
- end
26
-
27
- it "renders with inline layouts" do
28
- mock_app do
29
- layout { 'h1 { text "THIS. IS. "; yield }' }
30
- get('/') { markaby 'em "SPARTA"' }
31
- end
32
- get '/'
33
- assert ok?
34
- assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
35
- end
36
-
37
- it "renders with file layouts" do
38
- markaby_app { markaby 'text "Hello World"', :layout => :layout2 }
39
- assert ok?
40
- assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
41
- end
42
-
43
- it 'renders inline markaby blocks' do
44
- markaby_app { markaby { h1 'Hiya' } }
45
- assert ok?
46
- assert_equal "<h1>Hiya</h1>", body
47
- end
48
-
49
- it 'renders inline markaby blocks with inline layouts' do
50
- markaby_app do
51
- settings.layout { 'h1 { text "THIS. IS. "; yield }' }
52
- markaby { em 'SPARTA' }
53
- end
54
- assert ok?
55
- assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
56
- end
57
-
58
- it 'renders inline markaby blocks with file layouts' do
59
- markaby_app { markaby(:layout => :layout2) { text "Hello World" } }
60
- assert ok?
61
- assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
62
- end
63
-
64
- it "raises error if template not found" do
65
- mock_app { get('/') { markaby :no_such_template } }
66
- assert_raises(Errno::ENOENT) { get('/') }
67
- end
68
-
69
- it "allows passing locals" do
70
- markaby_app {
71
- markaby 'text value', :locals => { :value => 'foo' }
72
- }
73
- assert ok?
74
- assert_equal 'foo', body
75
- end
76
- end
77
-
78
- rescue LoadError
79
- warn "#{$!.to_s}: skipping markaby tests"
80
- end
@@ -1,85 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- MarkdownTest = proc do
4
- def markdown_app(&block)
5
- mock_app do
6
- set :views, File.dirname(__FILE__) + '/views'
7
- get('/', &block)
8
- end
9
- get '/'
10
- end
11
-
12
- def setup
13
- Tilt.prefer engine, 'markdown', 'mkd', 'md'
14
- super
15
- end
16
-
17
- it 'uses the correct engine' do
18
- assert_equal engine, Tilt[:md]
19
- assert_equal engine, Tilt[:mkd]
20
- assert_equal engine, Tilt[:markdown]
21
- end
22
-
23
- it 'renders inline markdown strings' do
24
- markdown_app { markdown '# Hiya' }
25
- assert ok?
26
- assert_like "<h1>Hiya</h1>\n", body
27
- end
28
-
29
- it 'renders .markdown files in views path' do
30
- markdown_app { markdown :hello }
31
- assert ok?
32
- assert_like "<h1>Hello From Markdown</h1>", body
33
- end
34
-
35
- it "raises error if template not found" do
36
- mock_app { get('/') { markdown :no_such_template } }
37
- assert_raises(Errno::ENOENT) { get('/') }
38
- end
39
-
40
- it "renders with inline layouts" do
41
- mock_app do
42
- layout { 'THIS. IS. #{yield.upcase}!' }
43
- get('/') { markdown 'Sparta', :layout_engine => :str }
44
- end
45
- get '/'
46
- assert ok?
47
- assert_like 'THIS. IS. <P>SPARTA</P>!', body
48
- end
49
-
50
- it "renders with file layouts" do
51
- markdown_app {
52
- markdown 'Hello World', :layout => :layout2, :layout_engine => :erb
53
- }
54
- assert ok?
55
- assert_body "ERB Layout!\n<p>Hello World</p>"
56
- end
57
-
58
- it "can be used in a nested fashion for partials and whatnot" do
59
- mock_app do
60
- template(:inner) { "hi" }
61
- template(:outer) { "<outer><%= markdown :inner %></outer>" }
62
- get('/') { erb :outer }
63
- end
64
-
65
- get '/'
66
- assert ok?
67
- assert_like '<outer><p>hi</p></outer>', body
68
- end
69
- end
70
-
71
- # Will generate RDiscountTest, KramdownTest, etc.
72
- map = Tilt.respond_to?(:lazy_map) ? Tilt.lazy_map['md'].map(&:first) : Tilt.mappings['md']
73
-
74
- map.each do |t|
75
- begin
76
- t = eval(t) if t.is_a? String
77
- t.new { "" }
78
- klass = Class.new(Minitest::Test) { define_method(:engine) { t }}
79
- klass.class_eval(&MarkdownTest)
80
- name = t.name[/[^:]+$/].sub(/Template$/, '') << "Test"
81
- Object.const_set name, klass
82
- rescue LoadError, NameError
83
- warn "#{$!}: skipping markdown tests with #{t}"
84
- end
85
- end