sinatra 1.4.8 → 2.0.0

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -47
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +41 -49
  5. data/LICENSE +4 -1
  6. data/MAINTENANCE.md +42 -0
  7. data/README.de.md +644 -436
  8. data/README.es.md +6 -6
  9. data/README.fr.md +9 -9
  10. data/README.hu.md +37 -3
  11. data/README.ja.md +103 -45
  12. data/README.ko.md +8 -8
  13. data/README.md +471 -363
  14. data/README.pt-br.md +3 -3
  15. data/README.pt-pt.md +2 -2
  16. data/README.ru.md +42 -64
  17. data/README.zh.md +8 -8
  18. data/Rakefile +72 -49
  19. data/SECURITY.md +35 -0
  20. data/lib/sinatra/base.rb +137 -195
  21. data/lib/sinatra/indifferent_hash.rb +150 -0
  22. data/lib/sinatra/main.rb +1 -0
  23. data/lib/sinatra/show_exceptions.rb +63 -55
  24. data/lib/sinatra/version.rb +1 -1
  25. data/sinatra.gemspec +19 -7
  26. metadata +30 -164
  27. data/lib/sinatra/ext.rb +0 -17
  28. data/test/asciidoctor_test.rb +0 -72
  29. data/test/base_test.rb +0 -167
  30. data/test/builder_test.rb +0 -91
  31. data/test/coffee_test.rb +0 -96
  32. data/test/compile_test.rb +0 -183
  33. data/test/contest.rb +0 -91
  34. data/test/creole_test.rb +0 -65
  35. data/test/delegator_test.rb +0 -160
  36. data/test/encoding_test.rb +0 -20
  37. data/test/erb_test.rb +0 -116
  38. data/test/extensions_test.rb +0 -98
  39. data/test/filter_test.rb +0 -487
  40. data/test/haml_test.rb +0 -109
  41. data/test/helper.rb +0 -132
  42. data/test/helpers_test.rb +0 -1917
  43. data/test/integration/app.rb +0 -79
  44. data/test/integration_helper.rb +0 -236
  45. data/test/integration_test.rb +0 -104
  46. data/test/less_test.rb +0 -69
  47. data/test/liquid_test.rb +0 -77
  48. data/test/mapped_error_test.rb +0 -285
  49. data/test/markaby_test.rb +0 -80
  50. data/test/markdown_test.rb +0 -85
  51. data/test/mediawiki_test.rb +0 -68
  52. data/test/middleware_test.rb +0 -68
  53. data/test/nokogiri_test.rb +0 -67
  54. data/test/public/favicon.ico +0 -0
  55. data/test/public/hello+world.txt +0 -1
  56. data/test/rabl_test.rb +0 -89
  57. data/test/rack_test.rb +0 -45
  58. data/test/radius_test.rb +0 -59
  59. data/test/rdoc_test.rb +0 -66
  60. data/test/readme_test.rb +0 -130
  61. data/test/request_test.rb +0 -100
  62. data/test/response_test.rb +0 -63
  63. data/test/result_test.rb +0 -76
  64. data/test/route_added_hook_test.rb +0 -59
  65. data/test/routing_test.rb +0 -1456
  66. data/test/sass_test.rb +0 -115
  67. data/test/scss_test.rb +0 -88
  68. data/test/server_test.rb +0 -56
  69. data/test/settings_test.rb +0 -582
  70. data/test/sinatra_test.rb +0 -12
  71. data/test/slim_test.rb +0 -102
  72. data/test/static_test.rb +0 -266
  73. data/test/streaming_test.rb +0 -149
  74. data/test/stylus_test.rb +0 -90
  75. data/test/templates_test.rb +0 -382
  76. data/test/textile_test.rb +0 -65
  77. data/test/views/a/in_a.str +0 -1
  78. data/test/views/ascii.erb +0 -2
  79. data/test/views/b/in_b.str +0 -1
  80. data/test/views/calc.html.erb +0 -1
  81. data/test/views/error.builder +0 -3
  82. data/test/views/error.erb +0 -3
  83. data/test/views/error.haml +0 -3
  84. data/test/views/error.sass +0 -2
  85. data/test/views/explicitly_nested.str +0 -1
  86. data/test/views/foo/hello.test +0 -1
  87. data/test/views/hello.asciidoc +0 -1
  88. data/test/views/hello.builder +0 -1
  89. data/test/views/hello.coffee +0 -1
  90. data/test/views/hello.creole +0 -1
  91. data/test/views/hello.erb +0 -1
  92. data/test/views/hello.haml +0 -1
  93. data/test/views/hello.less +0 -5
  94. data/test/views/hello.liquid +0 -1
  95. data/test/views/hello.mab +0 -1
  96. data/test/views/hello.md +0 -1
  97. data/test/views/hello.mediawiki +0 -1
  98. data/test/views/hello.nokogiri +0 -1
  99. data/test/views/hello.rabl +0 -2
  100. data/test/views/hello.radius +0 -1
  101. data/test/views/hello.rdoc +0 -1
  102. data/test/views/hello.sass +0 -2
  103. data/test/views/hello.scss +0 -3
  104. data/test/views/hello.slim +0 -1
  105. data/test/views/hello.str +0 -1
  106. data/test/views/hello.styl +0 -2
  107. data/test/views/hello.test +0 -1
  108. data/test/views/hello.textile +0 -1
  109. data/test/views/hello.wlang +0 -1
  110. data/test/views/hello.yajl +0 -1
  111. data/test/views/layout2.builder +0 -3
  112. data/test/views/layout2.erb +0 -2
  113. data/test/views/layout2.haml +0 -2
  114. data/test/views/layout2.liquid +0 -2
  115. data/test/views/layout2.mab +0 -2
  116. data/test/views/layout2.nokogiri +0 -3
  117. data/test/views/layout2.rabl +0 -3
  118. data/test/views/layout2.radius +0 -2
  119. data/test/views/layout2.slim +0 -3
  120. data/test/views/layout2.str +0 -2
  121. data/test/views/layout2.test +0 -1
  122. data/test/views/layout2.wlang +0 -2
  123. data/test/views/nested.str +0 -1
  124. data/test/views/utf8.erb +0 -2
  125. data/test/wlang_test.rb +0 -87
  126. data/test/yajl_test.rb +0 -86
@@ -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
data/test/markaby_test.rb DELETED
@@ -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
@@ -1,68 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'wikicloth'
5
-
6
- class MediaWikiTest < Minitest::Test
7
- def mediawiki_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 'supports both .mw and .mediawiki extensions' do
16
- assert_equal Tilt[:mw], Tilt[:mediawiki]
17
- end
18
-
19
- it 'renders inline mediawiki strings' do
20
- mediawiki_app { mediawiki "''Hiya''" }
21
- assert ok?
22
- assert_include body, '<i>Hiya</i>'
23
- end
24
-
25
- it 'renders .mediawiki files in views path' do
26
- mediawiki_app { mediawiki :hello }
27
- assert ok?
28
- assert_include body, "<i>Hello from MediaWiki</i>"
29
- end
30
-
31
- it 'raises error if template not found' do
32
- mock_app { get('/') { mediawiki :no_such_template } }
33
- assert_raises(Errno::ENOENT) { get('/') }
34
- end
35
-
36
- it 'renders with inline layouts' do
37
- mock_app do
38
- layout { 'THIS. IS. #{yield.upcase}!' }
39
- get('/') { mediawiki 'Sparta', :layout_engine => :str }
40
- end
41
- get '/'
42
- assert ok?
43
- assert_like 'THIS. IS. <P>SPARTA</P>!', body
44
- end
45
-
46
- it 'renders with file layouts' do
47
- mediawiki_app do
48
- mediawiki 'Hello World', :layout => :layout2, :layout_engine => :erb
49
- end
50
- assert ok?
51
- assert_body "ERB Layout!\n<p>Hello World</p>"
52
- end
53
-
54
- it 'can be used in a nested fashion for partials and whatnot' do
55
- mock_app do
56
- template(:inner) { "hi" }
57
- template(:outer) { "<outer><%= mediawiki :inner %></outer>" }
58
- get('/') { erb :outer }
59
- end
60
-
61
- get '/'
62
- assert ok?
63
- assert_like '<outer><p>hi</p></outer>', body
64
- end
65
- end
66
- rescue LoadError
67
- warn "#{$!.to_s}: skipping mediawiki tests"
68
- end
@@ -1,68 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class MiddlewareTest < Minitest::Test
4
- setup do
5
- @app = mock_app(Sinatra::Application) do
6
- get('/*')do
7
- response.headers['X-Tests'] = env['test.ran'].
8
- map { |n| n.split('::').last }.
9
- join(', ')
10
- env['PATH_INFO']
11
- end
12
- end
13
- end
14
-
15
- class MockMiddleware < Struct.new(:app)
16
- def call(env)
17
- (env['test.ran'] ||= []) << self.class.to_s
18
- app.call(env)
19
- end
20
- end
21
-
22
- class UpcaseMiddleware < MockMiddleware
23
- def call(env)
24
- env['PATH_INFO'] = env['PATH_INFO'].upcase
25
- super
26
- end
27
- end
28
-
29
- it "is added with Sinatra::Application.use" do
30
- @app.use UpcaseMiddleware
31
- get '/hello-world'
32
- assert ok?
33
- assert_equal '/HELLO-WORLD', body
34
- end
35
-
36
- class DowncaseMiddleware < MockMiddleware
37
- def call(env)
38
- env['PATH_INFO'] = env['PATH_INFO'].downcase
39
- super
40
- end
41
- end
42
-
43
- it "runs in the order defined" do
44
- @app.use UpcaseMiddleware
45
- @app.use DowncaseMiddleware
46
- get '/Foo'
47
- assert_equal "/foo", body
48
- assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
49
- end
50
-
51
- it "resets the prebuilt pipeline when new middleware is added" do
52
- @app.use UpcaseMiddleware
53
- get '/Foo'
54
- assert_equal "/FOO", body
55
- @app.use DowncaseMiddleware
56
- get '/Foo'
57
- assert_equal '/foo', body
58
- assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
59
- end
60
-
61
- it "works when app is used as middleware" do
62
- @app.use UpcaseMiddleware
63
- @app = @app.new
64
- get '/Foo'
65
- assert_equal "/FOO", body
66
- assert_equal "UpcaseMiddleware", response['X-Tests']
67
- end
68
- end
@@ -1,67 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'nokogiri'
5
-
6
- class NokogiriTest < Minitest::Test
7
- def nokogiri_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 Nokogiri strings' do
16
- nokogiri_app { nokogiri 'xml' }
17
- assert ok?
18
- assert_body %(<?xml version="1.0"?>\n)
19
- end
20
-
21
- it 'renders inline blocks' do
22
- nokogiri_app do
23
- @name = "Frank & Mary"
24
- nokogiri { |xml| xml.couple @name }
25
- end
26
- assert ok?
27
- assert_body %(<?xml version="1.0"?>\n<couple>Frank &amp; Mary</couple>\n)
28
- end
29
-
30
- it 'renders .nokogiri files in views path' do
31
- nokogiri_app do
32
- @name = "Blue"
33
- nokogiri :hello
34
- end
35
- assert ok?
36
- assert_body "<?xml version=\"1.0\"?>\n<exclaim>You're my boy, Blue!</exclaim>\n"
37
- end
38
-
39
- it "renders with inline layouts" do
40
- next if Tilt::VERSION <= "1.1"
41
- mock_app do
42
- layout { %(xml.layout { xml << yield }) }
43
- get('/') { nokogiri %(xml.em 'Hello World') }
44
- end
45
- get '/'
46
- assert ok?
47
- assert_body %(<?xml version="1.0"?>\n<layout>\n <em>Hello World</em>\n</layout>\n)
48
- end
49
-
50
- it "renders with file layouts" do
51
- next if Tilt::VERSION <= "1.1"
52
- nokogiri_app {
53
- nokogiri %(xml.em 'Hello World'), :layout => :layout2
54
- }
55
- assert ok?
56
- assert_body %(<?xml version="1.0"?>\n<layout>\n <em>Hello World</em>\n</layout>\n)
57
- end
58
-
59
- it "raises error if template not found" do
60
- mock_app { get('/') { nokogiri :no_such_template } }
61
- assert_raises(Errno::ENOENT) { get('/') }
62
- end
63
- end
64
-
65
- rescue LoadError
66
- warn "#{$!.to_s}: skipping nokogiri tests"
67
- end
File without changes
@@ -1 +0,0 @@
1
- This is a test intended for the + sign in urls for static serving