sinatra-contrib 1.4.7 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -16
- data/Rakefile +0 -1
- data/lib/sinatra/config_file.rb +8 -2
- data/lib/sinatra/content_for.rb +63 -1
- data/lib/sinatra/contrib.rb +1 -1
- data/lib/sinatra/contrib/version.rb +1 -12
- data/lib/sinatra/cookies.rb +1 -1
- data/lib/sinatra/link_header.rb +2 -2
- data/lib/sinatra/namespace.rb +90 -18
- data/lib/sinatra/reloader.rb +15 -1
- data/lib/sinatra/required_params.rb +71 -0
- data/lib/sinatra/respond_with.rb +7 -5
- data/sinatra-contrib.gemspec +14 -10
- data/spec/capture_spec.rb +5 -5
- data/spec/config_file/key_value.yml +1 -0
- data/spec/config_file_spec.rb +27 -13
- data/spec/content_for/footer.haml +1 -1
- data/spec/content_for/footer.slim +1 -1
- data/spec/content_for_spec.rb +65 -36
- data/spec/cookies_spec.rb +167 -173
- data/spec/extension_spec.rb +4 -4
- data/spec/json_spec.rb +11 -11
- data/spec/link_header_spec.rb +13 -13
- data/spec/multi_route_spec.rb +13 -13
- data/spec/namespace_spec.rb +190 -140
- data/spec/reloader_spec.rb +56 -31
- data/spec/required_params_spec.rb +68 -0
- data/spec/respond_with_spec.rb +58 -56
- data/spec/streaming_spec.rb +57 -57
- metadata +37 -22
- data/lib/sinatra/decompile.rb +0 -127
- data/spec/decompile_spec.rb +0 -43
data/spec/streaming_spec.rb
CHANGED
@@ -26,102 +26,102 @@ describe Sinatra::Streaming do
|
|
26
26
|
it 'runs the given block' do
|
27
27
|
ran = false
|
28
28
|
stream { ran = true }
|
29
|
-
ran.
|
29
|
+
expect(ran).to be true
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns the stream object' do
|
33
33
|
out = stream { }
|
34
|
-
out.
|
34
|
+
expect(out).to be_a(Sinatra::Helpers::Stream)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'fires a request against that stream' do
|
38
38
|
stream { |out| out << "Hello World!" }
|
39
|
-
last_response.
|
40
|
-
body.
|
39
|
+
expect(last_response).to be_ok
|
40
|
+
expect(body).to eq("Hello World!")
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'passes the stream object to the block' do
|
44
44
|
passed = nil
|
45
45
|
returned = stream { |out| passed = out }
|
46
|
-
passed.
|
46
|
+
expect(passed).to eq(returned)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
context Sinatra::Streaming::Stream do
|
51
51
|
it 'should extend the stream object' do
|
52
52
|
out = stream { }
|
53
|
-
out.
|
53
|
+
expect(out).to be_a(Sinatra::Streaming::Stream)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should not extend stream objects of other apps' do
|
57
57
|
out = nil
|
58
58
|
mock_app { get('/') { out = stream { }}}
|
59
59
|
get('/')
|
60
|
-
out.
|
61
|
-
out.
|
60
|
+
expect(out).to be_a(Sinatra::Helpers::Stream)
|
61
|
+
expect(out).not_to be_a(Sinatra::Streaming::Stream)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'app' do
|
66
66
|
it 'is the app instance the stream was created from' do
|
67
67
|
out = stream { }
|
68
|
-
out.app.
|
68
|
+
expect(out.app).to be_a(Sinatra::Base)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
context 'lineno' do
|
73
73
|
it 'defaults to 0' do
|
74
|
-
stream { }.lineno.
|
74
|
+
expect(stream { }.lineno).to eq(0)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'does not increase on write' do
|
78
78
|
stream do |out|
|
79
79
|
out << "many\nlines\n"
|
80
|
-
out.lineno.
|
80
|
+
expect(out.lineno).to eq(0)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'is writable' do
|
85
85
|
out = stream { }
|
86
86
|
out.lineno = 10
|
87
|
-
out.lineno.
|
87
|
+
expect(out.lineno).to eq(10)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
context 'pos' do
|
92
92
|
it 'defaults to 0' do
|
93
|
-
stream { }.pos.
|
93
|
+
expect(stream { }.pos).to eq(0)
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'increases when writing data' do
|
97
97
|
stream do |out|
|
98
|
-
out.pos.
|
98
|
+
expect(out.pos).to eq(0)
|
99
99
|
out << 'hi'
|
100
|
-
out.pos.
|
100
|
+
expect(out.pos).to eq(2)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'is writable' do
|
105
105
|
out = stream { }
|
106
106
|
out.pos = 10
|
107
|
-
out.pos.
|
107
|
+
expect(out.pos).to eq(10)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'aliased to #tell' do
|
111
111
|
out = stream { }
|
112
|
-
out.tell.
|
112
|
+
expect(out.tell).to eq(0)
|
113
113
|
out.pos = 10
|
114
|
-
out.tell.
|
114
|
+
expect(out.tell).to eq(10)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
context 'closed' do
|
119
119
|
it 'returns false while streaming' do
|
120
|
-
stream { |out| out.
|
120
|
+
stream { |out| expect(out).not_to be_closed }
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'returns true after streaming' do
|
124
|
-
stream {}.
|
124
|
+
expect(stream {}).to be_closed
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -131,7 +131,7 @@ describe Sinatra::Streaming do
|
|
131
131
|
out.map! { |s| s.upcase }
|
132
132
|
out << 'ok'
|
133
133
|
end
|
134
|
-
body.
|
134
|
+
expect(body).to eq("OK")
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'is chainable' do
|
@@ -140,7 +140,7 @@ describe Sinatra::Streaming do
|
|
140
140
|
out.map! { |s| s.reverse }
|
141
141
|
out << 'ok'
|
142
142
|
end
|
143
|
-
body.
|
143
|
+
expect(body).to eq("KO")
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'works with middleware' do
|
@@ -155,7 +155,7 @@ describe Sinatra::Streaming do
|
|
155
155
|
|
156
156
|
use middleware
|
157
157
|
stream { |out| out << "ok" }
|
158
|
-
body.
|
158
|
+
expect(body).to eq("OK")
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'modifies each value separately' do
|
@@ -163,7 +163,7 @@ describe Sinatra::Streaming do
|
|
163
163
|
out.map! { |s| s.reverse }
|
164
164
|
out << "ab" << "cd"
|
165
165
|
end
|
166
|
-
body.
|
166
|
+
expect(body).to eq("badc")
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
@@ -179,7 +179,7 @@ describe Sinatra::Streaming do
|
|
179
179
|
|
180
180
|
use middleware
|
181
181
|
stream { |out| out << "ok" }
|
182
|
-
body.
|
182
|
+
expect(body).to eq("OK")
|
183
183
|
end
|
184
184
|
|
185
185
|
it 'is chainable' do
|
@@ -193,7 +193,7 @@ describe Sinatra::Streaming do
|
|
193
193
|
|
194
194
|
use middleware
|
195
195
|
stream { |out| out << "ok" }
|
196
|
-
body.
|
196
|
+
expect(body).to eq("KO")
|
197
197
|
end
|
198
198
|
|
199
199
|
it 'can be written as each.map' do
|
@@ -207,7 +207,7 @@ describe Sinatra::Streaming do
|
|
207
207
|
|
208
208
|
use middleware
|
209
209
|
stream { |out| out << "ok" }
|
210
|
-
body.
|
210
|
+
expect(body).to eq("OK")
|
211
211
|
end
|
212
212
|
|
213
213
|
it 'does not modify the original body' do
|
@@ -215,101 +215,101 @@ describe Sinatra::Streaming do
|
|
215
215
|
out.map { |s| s.reverse }
|
216
216
|
out << 'ok'
|
217
217
|
end
|
218
|
-
body.
|
218
|
+
expect(body).to eq('ok')
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
222
|
context 'write' do
|
223
223
|
it 'writes to the stream' do
|
224
224
|
stream { |out| out.write 'hi' }
|
225
|
-
body.
|
225
|
+
expect(body).to eq('hi')
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'returns the number of bytes' do
|
229
229
|
stream do |out|
|
230
|
-
out.write('hi').
|
231
|
-
out.write('hello').
|
230
|
+
expect(out.write('hi')).to eq(2)
|
231
|
+
expect(out.write('hello')).to eq(5)
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'accepts non-string objects' do
|
236
236
|
stream do |out|
|
237
|
-
out.write(12).
|
237
|
+
expect(out.write(12)).to eq(2)
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'should be aliased to syswrite' do
|
242
|
-
stream { |out| out.syswrite('hi').
|
243
|
-
body.
|
242
|
+
stream { |out| expect(out.syswrite('hi')).to eq(2) }
|
243
|
+
expect(body).to eq('hi')
|
244
244
|
end
|
245
245
|
|
246
246
|
it 'should be aliased to write_nonblock' do
|
247
|
-
stream { |out| out.write_nonblock('hi').
|
248
|
-
body.
|
247
|
+
stream { |out| expect(out.write_nonblock('hi')).to eq(2) }
|
248
|
+
expect(body).to eq('hi')
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
252
|
context 'print' do
|
253
253
|
it 'writes to the stream' do
|
254
254
|
stream { |out| out.print('hi') }
|
255
|
-
body.
|
255
|
+
expect(body).to eq('hi')
|
256
256
|
end
|
257
257
|
|
258
258
|
it 'accepts multiple arguments' do
|
259
259
|
stream { |out| out.print(1, 2, 3, 4) }
|
260
|
-
body.
|
260
|
+
expect(body).to eq('1234')
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'returns nil' do
|
264
|
-
stream { |out| out.print('hi').
|
264
|
+
stream { |out| expect(out.print('hi')).to be_nil }
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
268
|
context 'printf' do
|
269
269
|
it 'writes to the stream' do
|
270
270
|
stream { |out| out.printf('hi') }
|
271
|
-
body.
|
271
|
+
expect(body).to eq('hi')
|
272
272
|
end
|
273
273
|
|
274
274
|
it 'interpolates the format string' do
|
275
275
|
stream { |out| out.printf("%s: %d", "answer", 42) }
|
276
|
-
body.
|
276
|
+
expect(body).to eq('answer: 42')
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'returns nil' do
|
280
|
-
stream { |out| out.printf('hi').
|
280
|
+
stream { |out| expect(out.printf('hi')).to be_nil }
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
284
|
context 'putc' do
|
285
285
|
it 'writes the first character of a string' do
|
286
286
|
stream { |out| out.putc('hi') }
|
287
|
-
body.
|
287
|
+
expect(body).to eq('h')
|
288
288
|
end
|
289
289
|
|
290
290
|
it 'writes the character corresponding to an integer' do
|
291
291
|
stream { |out| out.putc(42) }
|
292
|
-
body.
|
292
|
+
expect(body).to eq('*')
|
293
293
|
end
|
294
294
|
|
295
295
|
it 'returns nil' do
|
296
|
-
stream { |out| out.putc('hi').
|
296
|
+
stream { |out| expect(out.putc('hi')).to be_nil }
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
300
|
context 'puts' do
|
301
301
|
it 'writes to the stream' do
|
302
302
|
stream { |out| out.puts('hi') }
|
303
|
-
body.
|
303
|
+
expect(body).to eq("hi\n")
|
304
304
|
end
|
305
305
|
|
306
306
|
it 'accepts multiple arguments' do
|
307
307
|
stream { |out| out.puts(1, 2, 3, 4) }
|
308
|
-
body.
|
308
|
+
expect(body).to eq("1\n2\n3\n4\n")
|
309
309
|
end
|
310
310
|
|
311
311
|
it 'returns nil' do
|
312
|
-
stream { |out| out.puts('hi').
|
312
|
+
stream { |out| expect(out.puts('hi')).to be_nil }
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
@@ -317,15 +317,15 @@ describe Sinatra::Streaming do
|
|
317
317
|
it 'sets #closed? to true' do
|
318
318
|
stream do |out|
|
319
319
|
out.close
|
320
|
-
out.
|
320
|
+
expect(out).to be_closed
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
324
324
|
it 'sets #closed_write? to true' do
|
325
325
|
stream do |out|
|
326
|
-
out.
|
326
|
+
expect(out).not_to be_closed_write
|
327
327
|
out.close
|
328
|
-
out.
|
328
|
+
expect(out).to be_closed_write
|
329
329
|
end
|
330
330
|
end
|
331
331
|
|
@@ -334,7 +334,7 @@ describe Sinatra::Streaming do
|
|
334
334
|
fired = false
|
335
335
|
out.callback { fired = true }
|
336
336
|
out.close
|
337
|
-
fired.
|
337
|
+
expect(fired).to be true
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
@@ -354,7 +354,7 @@ describe Sinatra::Streaming do
|
|
354
354
|
end
|
355
355
|
|
356
356
|
context 'closed_read?' do
|
357
|
-
it('returns true') { stream { |out| out.
|
357
|
+
it('returns true') { stream { |out| expect(out).to be_closed_read }}
|
358
358
|
end
|
359
359
|
|
360
360
|
context 'rewind' do
|
@@ -362,7 +362,7 @@ describe Sinatra::Streaming do
|
|
362
362
|
stream do |out|
|
363
363
|
out << 'hi'
|
364
364
|
out.rewind
|
365
|
-
out.pos.
|
365
|
+
expect(out.pos).to eq(0)
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
@@ -370,7 +370,7 @@ describe Sinatra::Streaming do
|
|
370
370
|
stream do |out|
|
371
371
|
out.lineno = 10
|
372
372
|
out.rewind
|
373
|
-
out.lineno.
|
373
|
+
expect(out.lineno).to eq(0)
|
374
374
|
end
|
375
375
|
end
|
376
376
|
end
|
@@ -395,7 +395,7 @@ describe Sinatra::Streaming do
|
|
395
395
|
enum.each do |method|
|
396
396
|
context method do
|
397
397
|
it 'creates an Enumerator' do
|
398
|
-
stream { |out| out.public_send(method).
|
398
|
+
stream { |out| expect(out.public_send(method)).to be_a(Enumerator) }
|
399
399
|
end
|
400
400
|
|
401
401
|
it 'calling each raises the appropriate exception' do
|
@@ -408,7 +408,7 @@ describe Sinatra::Streaming do
|
|
408
408
|
dummies.each do |method|
|
409
409
|
context method do
|
410
410
|
it 'returns nil' do
|
411
|
-
stream { |out| out.public_send(method).
|
411
|
+
stream { |out| expect(out.public_send(method)).to be_nil }
|
412
412
|
end
|
413
413
|
end
|
414
414
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -57,22 +57,36 @@ authors:
|
|
57
57
|
autorequire:
|
58
58
|
bindir: bin
|
59
59
|
cert_chain: []
|
60
|
-
date: 2016-
|
60
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
61
61
|
dependencies:
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: sinatra
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0.beta1
|
69
69
|
type: :runtime
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0.beta1
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: mustermann
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.0.beta2
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
89
|
+
version: 1.0.0.beta2
|
76
90
|
- !ruby/object:Gem::Dependency
|
77
91
|
name: backports
|
78
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,16 +139,16 @@ dependencies:
|
|
125
139
|
name: rack-protection
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|
127
141
|
requirements:
|
128
|
-
- -
|
142
|
+
- - '='
|
129
143
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
144
|
+
version: 2.0.0.beta1
|
131
145
|
type: :runtime
|
132
146
|
prerelease: false
|
133
147
|
version_requirements: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- -
|
149
|
+
- - '='
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
151
|
+
version: 2.0.0.beta1
|
138
152
|
- !ruby/object:Gem::Dependency
|
139
153
|
name: multi_json
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,14 +169,14 @@ dependencies:
|
|
155
169
|
requirements:
|
156
170
|
- - "~>"
|
157
171
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
172
|
+
version: '3.4'
|
159
173
|
type: :development
|
160
174
|
prerelease: false
|
161
175
|
version_requirements: !ruby/object:Gem::Requirement
|
162
176
|
requirements:
|
163
177
|
- - "~>"
|
164
178
|
- !ruby/object:Gem::Version
|
165
|
-
version: '
|
179
|
+
version: '3.4'
|
166
180
|
- !ruby/object:Gem::Dependency
|
167
181
|
name: haml
|
168
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,16 +293,16 @@ dependencies:
|
|
279
293
|
name: RedCloth
|
280
294
|
requirement: !ruby/object:Gem::Requirement
|
281
295
|
requirements:
|
282
|
-
- - "
|
296
|
+
- - "~>"
|
283
297
|
- !ruby/object:Gem::Version
|
284
|
-
version:
|
298
|
+
version: 4.2.9
|
285
299
|
type: :development
|
286
300
|
prerelease: false
|
287
301
|
version_requirements: !ruby/object:Gem::Requirement
|
288
302
|
requirements:
|
289
|
-
- - "
|
303
|
+
- - "~>"
|
290
304
|
- !ruby/object:Gem::Version
|
291
|
-
version:
|
305
|
+
version: 4.2.9
|
292
306
|
- !ruby/object:Gem::Dependency
|
293
307
|
name: asciidoctor
|
294
308
|
requirement: !ruby/object:Gem::Requirement
|
@@ -474,7 +488,6 @@ files:
|
|
474
488
|
- lib/sinatra/contrib/version.rb
|
475
489
|
- lib/sinatra/cookies.rb
|
476
490
|
- lib/sinatra/custom_logger.rb
|
477
|
-
- lib/sinatra/decompile.rb
|
478
491
|
- lib/sinatra/engine_tracking.rb
|
479
492
|
- lib/sinatra/extension.rb
|
480
493
|
- lib/sinatra/json.rb
|
@@ -482,6 +495,7 @@ files:
|
|
482
495
|
- lib/sinatra/multi_route.rb
|
483
496
|
- lib/sinatra/namespace.rb
|
484
497
|
- lib/sinatra/reloader.rb
|
498
|
+
- lib/sinatra/required_params.rb
|
485
499
|
- lib/sinatra/respond_with.rb
|
486
500
|
- lib/sinatra/streaming.rb
|
487
501
|
- lib/sinatra/test_helpers.rb
|
@@ -529,7 +543,6 @@ files:
|
|
529
543
|
- spec/content_for_spec.rb
|
530
544
|
- spec/cookies_spec.rb
|
531
545
|
- spec/custom_logger_spec.rb
|
532
|
-
- spec/decompile_spec.rb
|
533
546
|
- spec/extension_spec.rb
|
534
547
|
- spec/json_spec.rb
|
535
548
|
- spec/link_header_spec.rb
|
@@ -540,6 +553,7 @@ files:
|
|
540
553
|
- spec/okjson.rb
|
541
554
|
- spec/reloader/app.rb.erb
|
542
555
|
- spec/reloader_spec.rb
|
556
|
+
- spec/required_params_spec.rb
|
543
557
|
- spec/respond_with/bar.erb
|
544
558
|
- spec/respond_with/bar.json.erb
|
545
559
|
- spec/respond_with/baz.yajl
|
@@ -560,16 +574,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
560
574
|
requirements:
|
561
575
|
- - ">="
|
562
576
|
- !ruby/object:Gem::Version
|
563
|
-
version:
|
577
|
+
version: 2.2.0
|
564
578
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
565
579
|
requirements:
|
566
|
-
- - "
|
580
|
+
- - ">"
|
567
581
|
- !ruby/object:Gem::Version
|
568
|
-
version:
|
582
|
+
version: 1.3.1
|
569
583
|
requirements: []
|
570
584
|
rubyforge_project:
|
571
|
-
rubygems_version: 2.5.
|
585
|
+
rubygems_version: 2.5.1
|
572
586
|
signing_key:
|
573
587
|
specification_version: 4
|
574
588
|
summary: Collection of useful Sinatra extensions
|
575
589
|
test_files: []
|
590
|
+
has_rdoc:
|