sinatra-acd 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/AUTHORS +61 -0
- data/CHANGES +1293 -0
- data/Gemfile +76 -0
- data/LICENSE +23 -0
- data/README.de.md +2864 -0
- data/README.es.md +2786 -0
- data/README.fr.md +2924 -0
- data/README.hu.md +694 -0
- data/README.ja.md +2726 -0
- data/README.ko.md +2832 -0
- data/README.md +2980 -0
- data/README.pt-br.md +965 -0
- data/README.pt-pt.md +791 -0
- data/README.ru.md +2799 -0
- data/README.zh.md +2158 -0
- data/Rakefile +199 -0
- data/examples/chat.rb +61 -0
- data/examples/simple.rb +3 -0
- data/examples/stream.ru +26 -0
- data/lib/sinatra.rb +4 -0
- data/lib/sinatra/base.rb +2044 -0
- data/lib/sinatra/images/404.png +0 -0
- data/lib/sinatra/images/500.png +0 -0
- data/lib/sinatra/main.rb +34 -0
- data/lib/sinatra/show_exceptions.rb +345 -0
- data/lib/sinatra/version.rb +3 -0
- data/sinatra.gemspec +19 -0
- data/test/asciidoctor_test.rb +72 -0
- data/test/base_test.rb +171 -0
- data/test/builder_test.rb +91 -0
- data/test/coffee_test.rb +90 -0
- data/test/compile_test.rb +183 -0
- data/test/contest.rb +100 -0
- data/test/creole_test.rb +65 -0
- data/test/delegator_test.rb +160 -0
- data/test/encoding_test.rb +20 -0
- data/test/erb_test.rb +116 -0
- data/test/extensions_test.rb +98 -0
- data/test/filter_test.rb +487 -0
- data/test/haml_test.rb +109 -0
- data/test/helper.rb +131 -0
- data/test/helpers_test.rb +1917 -0
- data/test/integration/app.rb +79 -0
- data/test/integration_helper.rb +236 -0
- data/test/integration_test.rb +104 -0
- data/test/less_test.rb +69 -0
- data/test/liquid_test.rb +77 -0
- data/test/mapped_error_test.rb +285 -0
- data/test/markaby_test.rb +80 -0
- data/test/markdown_test.rb +82 -0
- data/test/mediawiki_test.rb +68 -0
- data/test/middleware_test.rb +68 -0
- data/test/nokogiri_test.rb +67 -0
- data/test/public/favicon.ico +0 -0
- data/test/rabl_test.rb +89 -0
- data/test/rack_test.rb +45 -0
- data/test/radius_test.rb +59 -0
- data/test/rdoc_test.rb +66 -0
- data/test/readme_test.rb +130 -0
- data/test/request_test.rb +97 -0
- data/test/response_test.rb +63 -0
- data/test/result_test.rb +76 -0
- data/test/route_added_hook_test.rb +59 -0
- data/test/routing_test.rb +1412 -0
- data/test/sass_test.rb +115 -0
- data/test/scss_test.rb +88 -0
- data/test/server_test.rb +48 -0
- data/test/settings_test.rb +582 -0
- data/test/sinatra_test.rb +12 -0
- data/test/slim_test.rb +102 -0
- data/test/static_test.rb +236 -0
- data/test/streaming_test.rb +149 -0
- data/test/stylus_test.rb +90 -0
- data/test/templates_test.rb +382 -0
- data/test/textile_test.rb +65 -0
- data/test/views/a/in_a.str +1 -0
- data/test/views/ascii.erb +2 -0
- data/test/views/b/in_b.str +1 -0
- data/test/views/calc.html.erb +1 -0
- data/test/views/error.builder +3 -0
- data/test/views/error.erb +3 -0
- data/test/views/error.haml +3 -0
- data/test/views/error.sass +2 -0
- data/test/views/explicitly_nested.str +1 -0
- data/test/views/foo/hello.test +1 -0
- data/test/views/hello.asciidoc +1 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.coffee +1 -0
- data/test/views/hello.creole +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.less +5 -0
- data/test/views/hello.liquid +1 -0
- data/test/views/hello.mab +1 -0
- data/test/views/hello.md +1 -0
- data/test/views/hello.mediawiki +1 -0
- data/test/views/hello.nokogiri +1 -0
- data/test/views/hello.rabl +2 -0
- data/test/views/hello.radius +1 -0
- data/test/views/hello.rdoc +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.scss +3 -0
- data/test/views/hello.slim +1 -0
- data/test/views/hello.str +1 -0
- data/test/views/hello.styl +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/hello.textile +1 -0
- data/test/views/hello.wlang +1 -0
- data/test/views/hello.yajl +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.liquid +2 -0
- data/test/views/layout2.mab +2 -0
- data/test/views/layout2.nokogiri +3 -0
- data/test/views/layout2.rabl +3 -0
- data/test/views/layout2.radius +2 -0
- data/test/views/layout2.slim +3 -0
- data/test/views/layout2.str +2 -0
- data/test/views/layout2.test +1 -0
- data/test/views/layout2.wlang +2 -0
- data/test/views/nested.str +1 -0
- data/test/views/utf8.erb +2 -0
- data/test/wlang_test.rb +87 -0
- data/test/yajl_test.rb +86 -0
- metadata +280 -0
data/test/liquid_test.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'liquid'
|
5
|
+
|
6
|
+
class LiquidTest < Test::Unit::TestCase
|
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_raise(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 rendere 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
|
@@ -0,0 +1,285 @@
|
|
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 < Test::Unit::TestCase
|
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_raise(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
|
+
assert_nothing_raised { 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
|
+
assert_nothing_raised { 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
|
+
assert_nothing_raised { 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
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'markaby'
|
5
|
+
|
6
|
+
class MarkabyTest < Test::Unit::TestCase
|
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_raise(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
|
@@ -0,0 +1,82 @@
|
|
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_raise(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
|
+
Tilt.mappings['md'].each do |t|
|
73
|
+
begin
|
74
|
+
t.new { "" }
|
75
|
+
klass = Class.new(Test::Unit::TestCase) { define_method(:engine) { t }}
|
76
|
+
klass.class_eval(&MarkdownTest)
|
77
|
+
name = t.name[/[^:]+$/].sub(/Template$/, '') << "Test"
|
78
|
+
Object.const_set name, klass
|
79
|
+
rescue LoadError, NameError
|
80
|
+
warn "#{$!}: skipping markdown tests with #{t}"
|
81
|
+
end
|
82
|
+
end
|