grape 1.3.3 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/CONTRIBUTING.md +2 -1
  4. data/README.md +135 -23
  5. data/UPGRADING.md +237 -46
  6. data/grape.gemspec +5 -5
  7. data/lib/grape/api/instance.rb +34 -42
  8. data/lib/grape/api.rb +21 -16
  9. data/lib/grape/cookies.rb +2 -0
  10. data/lib/grape/dsl/callbacks.rb +1 -1
  11. data/lib/grape/dsl/desc.rb +3 -5
  12. data/lib/grape/dsl/headers.rb +5 -2
  13. data/lib/grape/dsl/helpers.rb +8 -5
  14. data/lib/grape/dsl/inside_route.rb +72 -53
  15. data/lib/grape/dsl/middleware.rb +4 -4
  16. data/lib/grape/dsl/parameters.rb +11 -7
  17. data/lib/grape/dsl/request_response.rb +9 -6
  18. data/lib/grape/dsl/routing.rb +8 -9
  19. data/lib/grape/dsl/settings.rb +5 -5
  20. data/lib/grape/dsl/validations.rb +18 -1
  21. data/lib/grape/eager_load.rb +1 -1
  22. data/lib/grape/endpoint.rb +29 -42
  23. data/lib/grape/error_formatter/json.rb +2 -6
  24. data/lib/grape/error_formatter/xml.rb +2 -6
  25. data/lib/grape/exceptions/empty_message_body.rb +11 -0
  26. data/lib/grape/exceptions/validation.rb +2 -3
  27. data/lib/grape/exceptions/validation_errors.rb +1 -1
  28. data/lib/grape/formatter/json.rb +1 -0
  29. data/lib/grape/formatter/serializable_hash.rb +2 -1
  30. data/lib/grape/formatter/xml.rb +1 -0
  31. data/lib/grape/locale/en.yml +1 -1
  32. data/lib/grape/middleware/auth/base.rb +3 -3
  33. data/lib/grape/middleware/auth/dsl.rb +7 -1
  34. data/lib/grape/middleware/base.rb +6 -3
  35. data/lib/grape/middleware/error.rb +11 -13
  36. data/lib/grape/middleware/formatter.rb +7 -7
  37. data/lib/grape/middleware/stack.rb +10 -3
  38. data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
  39. data/lib/grape/middleware/versioner/header.rb +6 -4
  40. data/lib/grape/middleware/versioner/param.rb +1 -0
  41. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
  42. data/lib/grape/middleware/versioner/path.rb +2 -0
  43. data/lib/grape/parser/json.rb +1 -1
  44. data/lib/grape/parser/xml.rb +1 -1
  45. data/lib/grape/path.rb +1 -0
  46. data/lib/grape/request.rb +4 -1
  47. data/lib/grape/router/attribute_translator.rb +3 -3
  48. data/lib/grape/router/pattern.rb +1 -1
  49. data/lib/grape/router/route.rb +2 -2
  50. data/lib/grape/router.rb +31 -30
  51. data/lib/grape/{serve_file → serve_stream}/file_body.rb +1 -1
  52. data/lib/grape/{serve_file → serve_stream}/sendfile_response.rb +1 -1
  53. data/lib/grape/{serve_file/file_response.rb → serve_stream/stream_response.rb} +8 -8
  54. data/lib/grape/util/base_inheritable.rb +2 -2
  55. data/lib/grape/util/inheritable_setting.rb +1 -3
  56. data/lib/grape/util/lazy_value.rb +4 -2
  57. data/lib/grape/util/strict_hash_configuration.rb +1 -1
  58. data/lib/grape/validations/attributes_iterator.rb +8 -0
  59. data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
  60. data/lib/grape/validations/params_scope.rb +97 -62
  61. data/lib/grape/validations/single_attribute_iterator.rb +1 -1
  62. data/lib/grape/validations/types/custom_type_coercer.rb +16 -3
  63. data/lib/grape/validations/types/dry_type_coercer.rb +1 -1
  64. data/lib/grape/validations/types/invalid_value.rb +24 -0
  65. data/lib/grape/validations/types/json.rb +2 -1
  66. data/lib/grape/validations/types/primitive_coercer.rb +4 -5
  67. data/lib/grape/validations/types.rb +1 -4
  68. data/lib/grape/validations/validator_factory.rb +1 -1
  69. data/lib/grape/validations/validators/all_or_none.rb +8 -5
  70. data/lib/grape/validations/validators/allow_blank.rb +9 -7
  71. data/lib/grape/validations/validators/as.rb +6 -8
  72. data/lib/grape/validations/validators/at_least_one_of.rb +7 -4
  73. data/lib/grape/validations/validators/base.rb +74 -69
  74. data/lib/grape/validations/validators/coerce.rb +63 -76
  75. data/lib/grape/validations/validators/default.rb +36 -34
  76. data/lib/grape/validations/validators/exactly_one_of.rb +9 -6
  77. data/lib/grape/validations/validators/except_values.rb +13 -11
  78. data/lib/grape/validations/validators/multiple_params_base.rb +24 -19
  79. data/lib/grape/validations/validators/mutual_exclusion.rb +8 -5
  80. data/lib/grape/validations/validators/presence.rb +7 -4
  81. data/lib/grape/validations/validators/regexp.rb +8 -5
  82. data/lib/grape/validations/validators/same_as.rb +18 -15
  83. data/lib/grape/validations/validators/values.rb +61 -56
  84. data/lib/grape/validations.rb +6 -0
  85. data/lib/grape/version.rb +1 -1
  86. data/lib/grape.rb +7 -3
  87. data/spec/grape/api/custom_validations_spec.rb +77 -45
  88. data/spec/grape/api/deeply_included_options_spec.rb +3 -3
  89. data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
  90. data/spec/grape/api/invalid_format_spec.rb +2 -0
  91. data/spec/grape/api/recognize_path_spec.rb +1 -1
  92. data/spec/grape/api/routes_with_requirements_spec.rb +8 -8
  93. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
  94. data/spec/grape/api_remount_spec.rb +25 -19
  95. data/spec/grape/api_spec.rb +576 -211
  96. data/spec/grape/dsl/callbacks_spec.rb +2 -1
  97. data/spec/grape/dsl/headers_spec.rb +39 -9
  98. data/spec/grape/dsl/helpers_spec.rb +3 -2
  99. data/spec/grape/dsl/inside_route_spec.rb +185 -34
  100. data/spec/grape/dsl/logger_spec.rb +16 -18
  101. data/spec/grape/dsl/middleware_spec.rb +2 -1
  102. data/spec/grape/dsl/parameters_spec.rb +2 -0
  103. data/spec/grape/dsl/request_response_spec.rb +1 -0
  104. data/spec/grape/dsl/routing_spec.rb +10 -7
  105. data/spec/grape/endpoint/declared_spec.rb +848 -0
  106. data/spec/grape/endpoint_spec.rb +77 -589
  107. data/spec/grape/entity_spec.rb +29 -23
  108. data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
  109. data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
  110. data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
  111. data/spec/grape/exceptions/validation_spec.rb +5 -3
  112. data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
  113. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
  114. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
  115. data/spec/grape/integration/rack_sendfile_spec.rb +13 -9
  116. data/spec/grape/loading_spec.rb +8 -8
  117. data/spec/grape/middleware/auth/dsl_spec.rb +15 -6
  118. data/spec/grape/middleware/auth/strategies_spec.rb +61 -21
  119. data/spec/grape/middleware/base_spec.rb +24 -15
  120. data/spec/grape/middleware/error_spec.rb +3 -3
  121. data/spec/grape/middleware/exception_spec.rb +111 -161
  122. data/spec/grape/middleware/formatter_spec.rb +28 -7
  123. data/spec/grape/middleware/globals_spec.rb +7 -4
  124. data/spec/grape/middleware/stack_spec.rb +15 -12
  125. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
  126. data/spec/grape/middleware/versioner/header_spec.rb +14 -13
  127. data/spec/grape/middleware/versioner/param_spec.rb +7 -1
  128. data/spec/grape/middleware/versioner/path_spec.rb +5 -1
  129. data/spec/grape/middleware/versioner_spec.rb +1 -1
  130. data/spec/grape/parser_spec.rb +4 -0
  131. data/spec/grape/path_spec.rb +52 -52
  132. data/spec/grape/presenters/presenter_spec.rb +7 -6
  133. data/spec/grape/request_spec.rb +6 -4
  134. data/spec/grape/util/inheritable_setting_spec.rb +7 -7
  135. data/spec/grape/util/inheritable_values_spec.rb +3 -2
  136. data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
  137. data/spec/grape/util/stackable_values_spec.rb +7 -5
  138. data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
  139. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +14 -3
  140. data/spec/grape/validations/params_scope_spec.rb +72 -10
  141. data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -6
  142. data/spec/grape/validations/types/primitive_coercer_spec.rb +63 -7
  143. data/spec/grape/validations/types_spec.rb +8 -8
  144. data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
  145. data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
  146. data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
  147. data/spec/grape/validations/validators/coerce_spec.rb +248 -33
  148. data/spec/grape/validations/validators/default_spec.rb +121 -78
  149. data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
  150. data/spec/grape/validations/validators/except_values_spec.rb +4 -3
  151. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
  152. data/spec/grape/validations/validators/presence_spec.rb +16 -1
  153. data/spec/grape/validations/validators/regexp_spec.rb +25 -31
  154. data/spec/grape/validations/validators/same_as_spec.rb +14 -20
  155. data/spec/grape/validations/validators/values_spec.rb +183 -178
  156. data/spec/grape/validations_spec.rb +342 -29
  157. data/spec/integration/eager_load/eager_load_spec.rb +15 -0
  158. data/spec/integration/multi_json/json_spec.rb +1 -1
  159. data/spec/integration/multi_xml/xml_spec.rb +1 -1
  160. data/spec/shared/versioning_examples.rb +32 -29
  161. data/spec/spec_helper.rb +12 -12
  162. data/spec/support/basic_auth_encode_helpers.rb +1 -1
  163. data/spec/support/chunks.rb +14 -0
  164. data/spec/support/versioned_helpers.rb +4 -6
  165. metadata +110 -102
@@ -12,7 +12,8 @@ module Grape
12
12
 
13
13
  describe Callbacks do
14
14
  subject { Class.new(CallbacksSpec::Dummy) }
15
- let(:proc) { ->() {} }
15
+
16
+ let(:proc) { -> {} }
16
17
 
17
18
  describe '.before' do
18
19
  it 'adds a block to "before"' do
@@ -12,21 +12,51 @@ module Grape
12
12
  describe Headers do
13
13
  subject { HeadersSpec::Dummy.new }
14
14
 
15
- describe '#header' do
16
- describe 'set' do
15
+ let(:header_data) do
16
+ { 'First Key' => 'First Value',
17
+ 'Second Key' => 'Second Value' }
18
+ end
19
+
20
+ context 'when headers are set' do
21
+ describe '#header' do
17
22
  before do
18
- subject.header 'Name', 'Value'
23
+ header_data.each { |k, v| subject.header(k, v) }
24
+ end
25
+
26
+ describe 'get' do
27
+ it 'returns a specifc value' do
28
+ expect(subject.header['First Key']).to eq 'First Value'
29
+ expect(subject.header['Second Key']).to eq 'Second Value'
30
+ end
31
+
32
+ it 'returns all set headers' do
33
+ expect(subject.header).to eq header_data
34
+ expect(subject.headers).to eq header_data
35
+ end
19
36
  end
20
37
 
21
- it 'returns value' do
22
- expect(subject.header['Name']).to eq 'Value'
23
- expect(subject.header('Name')).to eq 'Value'
38
+ describe 'set' do
39
+ it 'returns value' do
40
+ expect(subject.header('Third Key', 'Third Value'))
41
+ expect(subject.header['Third Key']).to eq 'Third Value'
42
+ end
43
+ end
44
+
45
+ describe 'delete' do
46
+ it 'deletes a header key-value pair' do
47
+ expect(subject.header('First Key')).to eq header_data['First Key']
48
+ expect(subject.header).not_to have_key('First Key')
49
+ end
24
50
  end
25
51
  end
52
+ end
26
53
 
27
- it 'returns nil' do
28
- expect(subject.header['Name']).to be nil
29
- expect(subject.header('Name')).to be nil
54
+ context 'when no headers are set' do
55
+ describe '#header' do
56
+ it 'returns nil' do
57
+ expect(subject.header['First Key']).to be nil
58
+ expect(subject.header('First Key')).to be nil
59
+ end
30
60
  end
31
61
  end
32
62
  end
@@ -34,6 +34,7 @@ module Grape
34
34
 
35
35
  describe Helpers do
36
36
  subject { Class.new(HelpersSpec::Dummy) }
37
+
37
38
  let(:proc) do
38
39
  lambda do |*|
39
40
  def test
@@ -54,7 +55,7 @@ module Grape
54
55
  it 'uses provided modules' do
55
56
  mod = Module.new
56
57
 
57
- expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.exactly(2).times
58
+ expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.twice
58
59
  expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
59
60
  subject.helpers(mod, &proc)
60
61
 
@@ -92,7 +93,7 @@ module Grape
92
93
  use :requires_toggle_prm
93
94
  end
94
95
  end
95
- end.to_not raise_exception
96
+ end.not_to raise_exception
96
97
  end
97
98
  end
98
99
  end
@@ -43,6 +43,7 @@ describe Grape::Endpoint do
43
43
  before do
44
44
  catch(:error) { subject.error! 'Not Found', 404 }
45
45
  end
46
+
46
47
  it 'sets status' do
47
48
  expect(subject.status).to eq 404
48
49
  end
@@ -53,6 +54,7 @@ describe Grape::Endpoint do
53
54
  subject.namespace_inheritable(:default_error_status, 500)
54
55
  catch(:error) { subject.error! 'Unknown' }
55
56
  end
57
+
56
58
  it 'sets status to default_error_status' do
57
59
  expect(subject.status).to eq 500
58
60
  end
@@ -136,7 +138,7 @@ describe Grape::Endpoint do
136
138
  end
137
139
 
138
140
  it 'accepts unknown Integer status codes' do
139
- expect { subject.status 210 }.to_not raise_error
141
+ expect { subject.status 210 }.not_to raise_error
140
142
  end
141
143
 
142
144
  it 'raises error if status is not a integer or symbol' do
@@ -203,80 +205,229 @@ describe Grape::Endpoint do
203
205
  end
204
206
 
205
207
  describe '#file' do
208
+ before do
209
+ allow(subject).to receive(:warn)
210
+ end
211
+
206
212
  describe 'set' do
207
213
  context 'as file path' do
208
214
  let(:file_path) { '/some/file/path' }
209
215
 
210
- let(:file_response) do
211
- file_body = Grape::ServeFile::FileBody.new(file_path)
212
- Grape::ServeFile::FileResponse.new(file_body)
213
- end
216
+ it 'emits a warning that this method is deprecated' do
217
+ expect(subject).to receive(:warn).with(/Use sendfile or stream/)
214
218
 
215
- before do
216
219
  subject.file file_path
217
220
  end
218
221
 
219
- it 'returns value wrapped in FileResponse' do
220
- expect(subject.file).to eq file_response
222
+ it 'forwards the call to sendfile' do
223
+ expect(subject).to receive(:sendfile).with(file_path)
224
+
225
+ subject.file file_path
221
226
  end
222
227
  end
223
228
 
224
229
  context 'as object (backward compatibility)' do
225
- let(:file_object) { Class.new }
230
+ let(:file_object) { double('StreamerObject', each: nil) }
231
+
232
+ it 'emits a warning that this method is deprecated' do
233
+ expect(subject).to receive(:warn).with(/Use stream to use a Stream object/)
234
+
235
+ subject.file file_object
236
+ end
237
+
238
+ it 'forwards the call to stream' do
239
+ expect(subject).to receive(:stream).with(file_object)
240
+
241
+ subject.file file_object
242
+ end
243
+ end
244
+ end
245
+
246
+ describe 'get' do
247
+ it 'emits a warning that this method is deprecated' do
248
+ expect(subject).to receive(:warn).with(/Use sendfile or stream/)
249
+
250
+ subject.file
251
+ end
252
+
253
+ it 'fowards call to sendfile' do
254
+ expect(subject).to receive(:sendfile)
255
+
256
+ subject.file
257
+ end
258
+ end
259
+ end
260
+
261
+ describe '#sendfile' do
262
+ describe 'set' do
263
+ context 'as file path' do
264
+ let(:file_path) { '/some/file/path' }
226
265
 
227
266
  let(:file_response) do
228
- Grape::ServeFile::FileResponse.new(file_object)
267
+ file_body = Grape::ServeStream::FileBody.new(file_path)
268
+ Grape::ServeStream::StreamResponse.new(file_body)
229
269
  end
230
270
 
231
271
  before do
232
- subject.file file_object
272
+ subject.header 'Cache-Control', 'cache'
273
+ subject.header 'Content-Length', 123
274
+ subject.header 'Transfer-Encoding', 'base64'
275
+ end
276
+
277
+ it 'sends no deprecation warnings' do
278
+ expect(subject).not_to receive(:warn)
279
+
280
+ subject.sendfile file_path
281
+ end
282
+
283
+ it 'returns value wrapped in StreamResponse' do
284
+ subject.sendfile file_path
285
+
286
+ expect(subject.sendfile).to eq file_response
287
+ end
288
+
289
+ it 'does not change the Cache-Control header' do
290
+ subject.sendfile file_path
291
+
292
+ expect(subject.header['Cache-Control']).to eq 'cache'
293
+ end
294
+
295
+ it 'does not change the Content-Length header' do
296
+ subject.sendfile file_path
297
+
298
+ expect(subject.header['Content-Length']).to eq 123
233
299
  end
234
300
 
235
- it 'returns value wrapped in FileResponse' do
236
- expect(subject.file).to eq file_response
301
+ it 'does not change the Transfer-Encoding header' do
302
+ subject.sendfile file_path
303
+
304
+ expect(subject.header['Transfer-Encoding']).to eq 'base64'
305
+ end
306
+ end
307
+
308
+ context 'as object' do
309
+ let(:file_object) { double('StreamerObject', each: nil) }
310
+
311
+ it 'raises an error that only a file path is supported' do
312
+ expect { subject.sendfile file_object }.to raise_error(ArgumentError, /Argument must be a file path/)
237
313
  end
238
314
  end
239
315
  end
240
316
 
241
317
  it 'returns default' do
242
- expect(subject.file).to be nil
318
+ expect(subject.sendfile).to be nil
243
319
  end
244
320
  end
245
321
 
246
322
  describe '#stream' do
247
323
  describe 'set' do
248
- let(:file_object) { Class.new }
324
+ context 'as a file path' do
325
+ let(:file_path) { '/some/file/path' }
249
326
 
250
- before do
251
- subject.header 'Cache-Control', 'cache'
252
- subject.header 'Content-Length', 123
253
- subject.header 'Transfer-Encoding', 'base64'
254
- subject.stream file_object
255
- end
327
+ let(:file_response) do
328
+ file_body = Grape::ServeStream::FileBody.new(file_path)
329
+ Grape::ServeStream::StreamResponse.new(file_body)
330
+ end
256
331
 
257
- it 'returns value wrapped in FileResponse' do
258
- expect(subject.stream).to eq Grape::ServeFile::FileResponse.new(file_object)
259
- end
332
+ before do
333
+ subject.header 'Cache-Control', 'cache'
334
+ subject.header 'Content-Length', 123
335
+ subject.header 'Transfer-Encoding', 'base64'
336
+ end
260
337
 
261
- it 'also sets result of file to value wrapped in FileResponse' do
262
- expect(subject.file).to eq Grape::ServeFile::FileResponse.new(file_object)
263
- end
338
+ it 'emits no deprecation warnings' do
339
+ expect(subject).not_to receive(:warn)
340
+
341
+ subject.stream file_path
342
+ end
343
+
344
+ it 'returns file body wrapped in StreamResponse' do
345
+ subject.stream file_path
346
+
347
+ expect(subject.stream).to eq file_response
348
+ end
349
+
350
+ it 'sets Cache-Control header to no-cache' do
351
+ subject.stream file_path
352
+
353
+ expect(subject.header['Cache-Control']).to eq 'no-cache'
354
+ end
355
+
356
+ it 'does not change Cache-Control header' do
357
+ subject.stream
358
+
359
+ expect(subject.header['Cache-Control']).to eq 'cache'
360
+ end
361
+
362
+ it 'sets Content-Length header to nil' do
363
+ subject.stream file_path
364
+
365
+ expect(subject.header['Content-Length']).to eq nil
366
+ end
264
367
 
265
- it 'sets Cache-Control header to no-cache' do
266
- expect(subject.header['Cache-Control']).to eq 'no-cache'
368
+ it 'sets Transfer-Encoding header to nil' do
369
+ subject.stream file_path
370
+
371
+ expect(subject.header['Transfer-Encoding']).to eq nil
372
+ end
267
373
  end
268
374
 
269
- it 'sets Content-Length header to nil' do
270
- expect(subject.header['Content-Length']).to eq nil
375
+ context 'as a stream object' do
376
+ let(:stream_object) { double('StreamerObject', each: nil) }
377
+
378
+ let(:stream_response) do
379
+ Grape::ServeStream::StreamResponse.new(stream_object)
380
+ end
381
+
382
+ before do
383
+ subject.header 'Cache-Control', 'cache'
384
+ subject.header 'Content-Length', 123
385
+ subject.header 'Transfer-Encoding', 'base64'
386
+ end
387
+
388
+ it 'emits no deprecation warnings' do
389
+ expect(subject).not_to receive(:warn)
390
+
391
+ subject.stream stream_object
392
+ end
393
+
394
+ it 'returns value wrapped in StreamResponse' do
395
+ subject.stream stream_object
396
+
397
+ expect(subject.stream).to eq stream_response
398
+ end
399
+
400
+ it 'sets Cache-Control header to no-cache' do
401
+ subject.stream stream_object
402
+
403
+ expect(subject.header['Cache-Control']).to eq 'no-cache'
404
+ end
405
+
406
+ it 'sets Content-Length header to nil' do
407
+ subject.stream stream_object
408
+
409
+ expect(subject.header['Content-Length']).to eq nil
410
+ end
411
+
412
+ it 'sets Transfer-Encoding header to nil' do
413
+ subject.stream stream_object
414
+
415
+ expect(subject.header['Transfer-Encoding']).to eq nil
416
+ end
271
417
  end
272
418
 
273
- it 'sets Transfer-Encoding header to nil' do
274
- expect(subject.header['Transfer-Encoding']).to eq nil
419
+ context 'as a non-stream object' do
420
+ let(:non_stream_object) { double('NonStreamerObject') }
421
+
422
+ it 'raises an error that the object must implement :each' do
423
+ expect { subject.stream non_stream_object }.to raise_error(ArgumentError, /:each/)
424
+ end
275
425
  end
276
426
  end
277
427
 
278
428
  it 'returns default' do
279
- expect(subject.file).to be nil
429
+ expect(subject.stream).to be nil
430
+ expect(subject.header['Cache-Control']).to eq nil
280
431
  end
281
432
  end
282
433
 
@@ -2,27 +2,25 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- module Grape
6
- module DSL
7
- module LoggerSpec
8
- class Dummy
9
- extend Grape::DSL::Logger
10
- end
5
+ describe Grape::DSL::Logger do
6
+ subject { Class.new(dummy_logger) }
7
+
8
+ let(:dummy_logger) do
9
+ Class.new do
10
+ extend Grape::DSL::Logger
11
11
  end
12
- describe Logger do
13
- subject { Class.new(LoggerSpec::Dummy) }
14
- let(:logger) { double(:logger) }
12
+ end
15
13
 
16
- describe '.logger' do
17
- it 'sets a logger' do
18
- subject.logger logger
19
- expect(subject.logger).to eq logger
20
- end
14
+ let(:logger) { instance_double(::Logger) }
15
+
16
+ describe '.logger' do
17
+ it 'sets a logger' do
18
+ subject.logger logger
19
+ expect(subject.logger).to eq logger
20
+ end
21
21
 
22
- it 'returns a logger' do
23
- expect(subject.logger(logger)).to eq logger
24
- end
25
- end
22
+ it 'returns a logger' do
23
+ expect(subject.logger(logger)).to eq logger
26
24
  end
27
25
  end
28
26
  end
@@ -12,7 +12,8 @@ module Grape
12
12
 
13
13
  describe Middleware do
14
14
  subject { Class.new(MiddlewareSpec::Dummy) }
15
- let(:proc) { ->() {} }
15
+
16
+ let(:proc) { -> {} }
16
17
  let(:foo_middleware) { Class.new }
17
18
  let(:bar_middleware) { Class.new }
18
19
 
@@ -40,6 +40,7 @@ module Grape
40
40
 
41
41
  def extract_message_option(attrs)
42
42
  return nil unless attrs.is_a?(Array)
43
+
43
44
  opts = attrs.last.is_a?(Hash) ? attrs.pop : {}
44
45
  opts.key?(:message) && !opts[:message].nil? ? opts.delete(:message) : nil
45
46
  end
@@ -54,6 +55,7 @@ module Grape
54
55
  allow_message_expectations_on_nil
55
56
  allow(subject.api).to receive(:namespace_stackable).with(:named_params)
56
57
  end
58
+
57
59
  let(:options) { { option: 'value' } }
58
60
  let(:named_params) { { params_group: proc {} } }
59
61
 
@@ -20,6 +20,7 @@ module Grape
20
20
 
21
21
  describe RequestResponse do
22
22
  subject { Class.new(RequestResponseSpec::Dummy) }
23
+
23
24
  let(:c_type) { 'application/json' }
24
25
  let(:format) { 'txt' }
25
26
 
@@ -12,7 +12,8 @@ module Grape
12
12
 
13
13
  describe Routing do
14
14
  subject { Class.new(RoutingSpec::Dummy) }
15
- let(:proc) { ->() {} }
15
+
16
+ let(:proc) { -> {} }
16
17
  let(:options) { { a: :b } }
17
18
  let(:path) { '/dummy' }
18
19
 
@@ -109,7 +110,7 @@ module Grape
109
110
  it 'does not duplicate identical endpoints' do
110
111
  subject.route(:any)
111
112
  expect { subject.route(:any) }
112
- .to_not change(subject.endpoints, :count)
113
+ .not_to change(subject.endpoints, :count)
113
114
  end
114
115
 
115
116
  it 'generates correct endpoint options' do
@@ -233,21 +234,23 @@ module Grape
233
234
  allow(subject).to receive(:prepare_routes).and_return(routes)
234
235
  subject.routes
235
236
  end
236
- it 'it does not call prepare_routes again' do
237
- expect(subject).to_not receive(:prepare_routes)
237
+
238
+ it 'does not call prepare_routes again' do
239
+ expect(subject).not_to receive(:prepare_routes)
238
240
  expect(subject.routes).to eq routes
239
241
  end
240
242
  end
241
243
  end
242
244
 
243
245
  describe '.route_param' do
246
+ let!(:options) { { requirements: regex } }
247
+ let(:regex) { /(.*)/ }
248
+
244
249
  it 'calls #namespace with given params' do
245
250
  expect(subject).to receive(:namespace).with(':foo', {}).and_yield
246
251
  subject.route_param('foo', {}, &proc {})
247
252
  end
248
253
 
249
- let(:regex) { /(.*)/ }
250
- let!(:options) { { requirements: regex } }
251
254
  it 'nests requirements option under param name' do
252
255
  expect(subject).to receive(:namespace) do |_param, options|
253
256
  expect(options[:requirements][:foo]).to eq regex
@@ -258,7 +261,7 @@ module Grape
258
261
  it 'does not modify options parameter' do
259
262
  allow(subject).to receive(:namespace)
260
263
  expect { subject.route_param('foo', options, &proc {}) }
261
- .to_not change { options }
264
+ .not_to change { options }
262
265
  end
263
266
  end
264
267