grape 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/README.md +120 -19
  5. data/UPGRADING.md +19 -4
  6. data/lib/grape/api/instance.rb +1 -1
  7. data/lib/grape/dsl/api.rb +0 -2
  8. data/lib/grape/dsl/callbacks.rb +0 -2
  9. data/lib/grape/dsl/configuration.rb +0 -2
  10. data/lib/grape/dsl/desc.rb +0 -15
  11. data/lib/grape/dsl/helpers.rb +0 -2
  12. data/lib/grape/dsl/inside_route.rb +33 -29
  13. data/lib/grape/dsl/middleware.rb +0 -2
  14. data/lib/grape/dsl/parameters.rb +5 -7
  15. data/lib/grape/dsl/request_response.rb +0 -2
  16. data/lib/grape/dsl/routing.rb +4 -2
  17. data/lib/grape/dsl/settings.rb +0 -2
  18. data/lib/grape/dsl/validations.rb +0 -15
  19. data/lib/grape/error_formatter/json.rb +7 -1
  20. data/lib/grape/exceptions/base.rb +2 -2
  21. data/lib/grape/exceptions/missing_group_type.rb +8 -1
  22. data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
  23. data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
  24. data/lib/grape/exceptions/validation.rb +0 -4
  25. data/lib/grape/locale/en.yml +9 -8
  26. data/lib/grape/middleware/auth/dsl.rb +0 -1
  27. data/lib/grape/middleware/error.rb +2 -2
  28. data/lib/grape/request.rb +2 -0
  29. data/lib/grape/validations/attributes_doc.rb +58 -0
  30. data/lib/grape/validations/params_scope.rb +66 -40
  31. data/lib/grape/validations/types/array_coercer.rb +2 -2
  32. data/lib/grape/validations/types/build_coercer.rb +94 -0
  33. data/lib/grape/validations/types/dry_type_coercer.rb +13 -8
  34. data/lib/grape/validations/types/json.rb +2 -0
  35. data/lib/grape/validations/types/primitive_coercer.rb +20 -10
  36. data/lib/grape/validations/types/set_coercer.rb +3 -2
  37. data/lib/grape/validations/types.rb +20 -26
  38. data/lib/grape/validations/validators/base.rb +7 -0
  39. data/lib/grape/validations.rb +16 -6
  40. data/lib/grape/version.rb +1 -1
  41. data/lib/grape.rb +20 -15
  42. data/spec/grape/api/custom_validations_spec.rb +41 -2
  43. data/spec/grape/api/deeply_included_options_spec.rb +0 -2
  44. data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -2
  45. data/spec/grape/api/documentation_spec.rb +59 -0
  46. data/spec/grape/api/inherited_helpers_spec.rb +0 -2
  47. data/spec/grape/api/instance_spec.rb +0 -1
  48. data/spec/grape/api/invalid_format_spec.rb +0 -2
  49. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
  50. data/spec/grape/api/nested_helpers_spec.rb +0 -2
  51. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
  52. data/spec/grape/api/parameters_modification_spec.rb +0 -2
  53. data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
  54. data/spec/grape/api/recognize_path_spec.rb +0 -2
  55. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
  56. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
  57. data/spec/grape/api/routes_with_requirements_spec.rb +0 -2
  58. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -2
  59. data/spec/grape/api/shared_helpers_spec.rb +0 -2
  60. data/spec/grape/api_remount_spec.rb +0 -1
  61. data/spec/grape/api_spec.rb +18 -5
  62. data/spec/grape/config_spec.rb +0 -2
  63. data/spec/grape/dsl/callbacks_spec.rb +0 -2
  64. data/spec/grape/dsl/configuration_spec.rb +0 -2
  65. data/spec/grape/dsl/desc_spec.rb +0 -2
  66. data/spec/grape/dsl/headers_spec.rb +2 -4
  67. data/spec/grape/dsl/helpers_spec.rb +0 -2
  68. data/spec/grape/dsl/inside_route_spec.rb +10 -12
  69. data/spec/grape/dsl/logger_spec.rb +0 -2
  70. data/spec/grape/dsl/middleware_spec.rb +0 -2
  71. data/spec/grape/dsl/parameters_spec.rb +0 -2
  72. data/spec/grape/dsl/request_response_spec.rb +6 -8
  73. data/spec/grape/dsl/routing_spec.rb +1 -3
  74. data/spec/grape/dsl/settings_spec.rb +0 -2
  75. data/spec/grape/dsl/validations_spec.rb +0 -17
  76. data/spec/grape/endpoint/declared_spec.rb +2 -4
  77. data/spec/grape/endpoint_spec.rb +22 -3
  78. data/spec/grape/entity_spec.rb +0 -1
  79. data/spec/grape/exceptions/base_spec.rb +16 -2
  80. data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -2
  81. data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -2
  82. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
  83. data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
  84. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
  85. data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
  86. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
  87. data/spec/grape/exceptions/missing_option_spec.rb +1 -3
  88. data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
  89. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
  90. data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
  91. data/spec/grape/exceptions/validation_errors_spec.rb +0 -1
  92. data/spec/grape/exceptions/validation_spec.rb +1 -3
  93. data/spec/grape/extensions/param_builders/hash_spec.rb +0 -2
  94. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -2
  95. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -2
  96. data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
  97. data/spec/grape/integration/rack_sendfile_spec.rb +0 -2
  98. data/spec/grape/integration/rack_spec.rb +0 -2
  99. data/spec/grape/loading_spec.rb +0 -2
  100. data/spec/grape/middleware/auth/base_spec.rb +0 -1
  101. data/spec/grape/middleware/auth/dsl_spec.rb +0 -2
  102. data/spec/grape/middleware/auth/strategies_spec.rb +0 -2
  103. data/spec/grape/middleware/base_spec.rb +0 -2
  104. data/spec/grape/middleware/error_spec.rb +6 -1
  105. data/spec/grape/middleware/exception_spec.rb +0 -2
  106. data/spec/grape/middleware/formatter_spec.rb +0 -2
  107. data/spec/grape/middleware/globals_spec.rb +0 -2
  108. data/spec/grape/middleware/stack_spec.rb +0 -2
  109. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -2
  110. data/spec/grape/middleware/versioner/header_spec.rb +18 -4
  111. data/spec/grape/middleware/versioner/param_spec.rb +0 -2
  112. data/spec/grape/middleware/versioner/path_spec.rb +0 -2
  113. data/spec/grape/middleware/versioner_spec.rb +0 -2
  114. data/spec/grape/named_api_spec.rb +0 -2
  115. data/spec/grape/parser_spec.rb +0 -2
  116. data/spec/grape/path_spec.rb +0 -2
  117. data/spec/grape/presenters/presenter_spec.rb +0 -2
  118. data/spec/grape/request_spec.rb +0 -2
  119. data/spec/grape/util/inheritable_setting_spec.rb +0 -1
  120. data/spec/grape/util/inheritable_values_spec.rb +0 -1
  121. data/spec/grape/util/reverse_stackable_values_spec.rb +0 -1
  122. data/spec/grape/util/stackable_values_spec.rb +0 -1
  123. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
  124. data/spec/grape/validations/attributes_doc_spec.rb +153 -0
  125. data/spec/grape/validations/attributes_iterator_spec.rb +0 -2
  126. data/spec/grape/validations/instance_behaivour_spec.rb +0 -2
  127. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -2
  128. data/spec/grape/validations/params_scope_spec.rb +315 -86
  129. data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -2
  130. data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
  131. data/spec/grape/validations/types/primitive_coercer_spec.rb +20 -5
  132. data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
  133. data/spec/grape/validations/types_spec.rb +28 -2
  134. data/spec/grape/validations/validators/all_or_none_spec.rb +0 -2
  135. data/spec/grape/validations/validators/allow_blank_spec.rb +0 -2
  136. data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -2
  137. data/spec/grape/validations/validators/coerce_spec.rb +0 -2
  138. data/spec/grape/validations/validators/default_spec.rb +0 -2
  139. data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -2
  140. data/spec/grape/validations/validators/except_values_spec.rb +0 -2
  141. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -2
  142. data/spec/grape/validations/validators/presence_spec.rb +0 -2
  143. data/spec/grape/validations/validators/regexp_spec.rb +0 -2
  144. data/spec/grape/validations/validators/same_as_spec.rb +0 -2
  145. data/spec/grape/validations/validators/values_spec.rb +0 -2
  146. data/spec/grape/validations_spec.rb +50 -22
  147. data/spec/integration/multi_json/json_spec.rb +0 -2
  148. data/spec/integration/multi_xml/xml_spec.rb +0 -2
  149. data/spec/spec_helper.rb +9 -4
  150. metadata +17 -8
  151. data/spec/support/eager_load.rb +0 -19
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module InsideRouteSpec
@@ -25,7 +23,7 @@ describe Grape::Endpoint do
25
23
 
26
24
  describe '#version' do
27
25
  it 'defaults to nil' do
28
- expect(subject.version).to be nil
26
+ expect(subject.version).to be_nil
29
27
  end
30
28
 
31
29
  it 'returns env[api.version]' do
@@ -167,7 +165,7 @@ describe Grape::Endpoint do
167
165
  end
168
166
 
169
167
  it 'returns default' do
170
- expect(subject.content_type).to be nil
168
+ expect(subject.content_type).to be_nil
171
169
  end
172
170
  end
173
171
 
@@ -200,7 +198,7 @@ describe Grape::Endpoint do
200
198
  end
201
199
 
202
200
  it 'returns default' do
203
- expect(subject.body).to be nil
201
+ expect(subject.body).to be_nil
204
202
  end
205
203
  end
206
204
 
@@ -315,7 +313,7 @@ describe Grape::Endpoint do
315
313
  end
316
314
 
317
315
  it 'returns default' do
318
- expect(subject.sendfile).to be nil
316
+ expect(subject.sendfile).to be_nil
319
317
  end
320
318
  end
321
319
 
@@ -362,13 +360,13 @@ describe Grape::Endpoint do
362
360
  it 'sets Content-Length header to nil' do
363
361
  subject.stream file_path
364
362
 
365
- expect(subject.header['Content-Length']).to eq nil
363
+ expect(subject.header['Content-Length']).to be_nil
366
364
  end
367
365
 
368
366
  it 'sets Transfer-Encoding header to nil' do
369
367
  subject.stream file_path
370
368
 
371
- expect(subject.header['Transfer-Encoding']).to eq nil
369
+ expect(subject.header['Transfer-Encoding']).to be_nil
372
370
  end
373
371
  end
374
372
 
@@ -406,13 +404,13 @@ describe Grape::Endpoint do
406
404
  it 'sets Content-Length header to nil' do
407
405
  subject.stream stream_object
408
406
 
409
- expect(subject.header['Content-Length']).to eq nil
407
+ expect(subject.header['Content-Length']).to be_nil
410
408
  end
411
409
 
412
410
  it 'sets Transfer-Encoding header to nil' do
413
411
  subject.stream stream_object
414
412
 
415
- expect(subject.header['Transfer-Encoding']).to eq nil
413
+ expect(subject.header['Transfer-Encoding']).to be_nil
416
414
  end
417
415
  end
418
416
 
@@ -426,8 +424,8 @@ describe Grape::Endpoint do
426
424
  end
427
425
 
428
426
  it 'returns default' do
429
- expect(subject.stream).to be nil
430
- expect(subject.header['Cache-Control']).to eq nil
427
+ expect(subject.stream).to be_nil
428
+ expect(subject.header['Cache-Control']).to be_nil
431
429
  end
432
430
  end
433
431
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::DSL::Logger do
6
4
  subject { Class.new(dummy_logger) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module MiddlewareSpec
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module ParametersSpec
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module RequestResponseSpec
@@ -162,34 +160,34 @@ module Grape
162
160
 
163
161
  describe 'list of exceptions is passed' do
164
162
  it 'sets hash of exceptions as rescue handlers' do
165
- expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, StandardError => nil)
163
+ expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => nil })
166
164
  expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
167
165
  subject.rescue_from StandardError
168
166
  end
169
167
 
170
168
  it 'rescues only base handlers if rescue_subclasses: false option is passed' do
171
- expect(subject).to receive(:namespace_reverse_stackable).with(:base_only_rescue_handlers, StandardError => nil)
172
- expect(subject).to receive(:namespace_stackable).with(:rescue_options, rescue_subclasses: false)
169
+ expect(subject).to receive(:namespace_reverse_stackable).with(:base_only_rescue_handlers, { StandardError => nil })
170
+ expect(subject).to receive(:namespace_stackable).with(:rescue_options, { rescue_subclasses: false })
173
171
  subject.rescue_from StandardError, rescue_subclasses: false
174
172
  end
175
173
 
176
174
  it 'sets given proc as rescue handler for each key in hash' do
177
175
  rescue_handler_proc = proc {}
178
- expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
176
+ expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => rescue_handler_proc })
179
177
  expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
180
178
  subject.rescue_from StandardError, rescue_handler_proc
181
179
  end
182
180
 
183
181
  it 'sets given block as rescue handler for each key in hash' do
184
182
  rescue_handler_proc = proc {}
185
- expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
183
+ expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => rescue_handler_proc })
186
184
  expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
187
185
  subject.rescue_from StandardError, &rescue_handler_proc
188
186
  end
189
187
 
190
188
  it 'sets a rescue handler declared through :with option for each key in hash' do
191
189
  with_block = -> { 'hello' }
192
- expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, StandardError => an_instance_of(Proc))
190
+ expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => an_instance_of(Proc) })
193
191
  expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
194
192
  subject.rescue_from StandardError, with: with_block
195
193
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module RoutingSpec
@@ -21,7 +19,7 @@ module Grape
21
19
  it 'sets a version for route' do
22
20
  version = 'v1'
23
21
  expect(subject).to receive(:namespace_inheritable).with(:version, [version])
24
- expect(subject).to receive(:namespace_inheritable).with(:version_options, using: :path)
22
+ expect(subject).to receive(:namespace_inheritable).with(:version_options, { using: :path })
25
23
  expect(subject.version(version)).to eq(version)
26
24
  end
27
25
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module SettingsSpec
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module DSL
7
5
  module ValidationsSpec
@@ -38,10 +36,6 @@ module Grape
38
36
  expect(subject.namespace_stackable(:params)).to eq []
39
37
  end
40
38
 
41
- it 'resets documentation params' do
42
- expect(subject.route_setting(:description)[:params]).to be_nil
43
- end
44
-
45
39
  it 'does not reset documentation description' do
46
40
  expect(subject.route_setting(:description)[:description]).to eq 'lol'
47
41
  end
@@ -56,17 +50,6 @@ module Grape
56
50
  expect { subject.params { raise 'foo' } }.to raise_error RuntimeError, 'foo'
57
51
  end
58
52
  end
59
-
60
- describe '.document_attribute' do
61
- before do
62
- subject.document_attribute([full_name: 'xxx'], foo: 'bar')
63
- end
64
-
65
- it 'creates a param documentation' do
66
- expect(subject.namespace_stackable(:params)).to eq(['xxx' => { foo: 'bar' }])
67
- expect(subject.route_setting(:description)).to eq(params: { 'xxx' => { foo: 'bar' } })
68
- end
69
- end
70
53
  end
71
54
  end
72
55
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Endpoint do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -249,7 +247,7 @@ describe Grape::Endpoint do
249
247
  end
250
248
  get '/declared?first=one&other=two'
251
249
  expect(last_response.status).to eq(200)
252
- expect(JSON.parse(last_response.body).key?(:other)).to eq false
250
+ expect(JSON.parse(last_response.body).key?(:other)).to be false
253
251
  end
254
252
 
255
253
  it 'stringifies if that option is passed' do
@@ -522,7 +520,7 @@ describe Grape::Endpoint do
522
520
  json = JSON.parse(last_response.body, symbolize_names: true)
523
521
 
524
522
  expect(json[:declared_params][:id]).to eq 123
525
- expect(json[:declared_params_no_parent][:id]).to eq nil
523
+ expect(json[:declared_params_no_parent][:id]).to be_nil
526
524
  end
527
525
  end
528
526
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Endpoint do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -434,7 +432,28 @@ describe Grape::Endpoint do
434
432
  end
435
433
  post '/upload', { file: '' }, 'CONTENT_TYPE' => 'multipart/form-data; boundary=foobar'
436
434
  expect(last_response.status).to eq(400)
437
- expect(last_response.body).to eq('Empty message body supplied with multipart/form-data; boundary=foobar content-type')
435
+ expect(last_response.body).to eq('empty message body supplied with multipart/form-data; boundary=foobar content-type')
436
+ end
437
+ end
438
+
439
+ context 'when the limit on multipart files is exceeded' do
440
+ around do |example|
441
+ limit = Rack::Utils.multipart_part_limit
442
+ Rack::Utils.multipart_part_limit = 1
443
+ example.run
444
+ Rack::Utils.multipart_part_limit = limit
445
+ end
446
+
447
+ it 'returns a 413 if given too many multipart files' do
448
+ subject.params do
449
+ requires :file, type: Rack::Multipart::UploadedFile
450
+ end
451
+ subject.post '/upload' do
452
+ params[:file][:filename]
453
+ end
454
+ post '/upload', { file: Rack::Test::UploadedFile.new(__FILE__, 'text/plain'), extra: Rack::Test::UploadedFile.new(__FILE__, 'text/plain') }
455
+ expect(last_response.status).to eq(413)
456
+ expect(last_response.body).to eq("the number of uploaded files exceeded the system's configured limit (1)")
438
457
  end
439
458
  end
440
459
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  require 'grape_entity'
5
4
 
6
5
  describe Grape::Entity do
@@ -1,8 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::Base do
4
+ describe '#to_s' do
5
+ subject { described_class.new(message: message).to_s }
6
+
7
+ let(:message) { 'a_message' }
8
+
9
+ it { is_expected.to eq(message) }
10
+ end
11
+
12
+ describe '#message' do
13
+ subject { described_class.new(message: message).message }
14
+
15
+ let(:message) { 'a_message' }
16
+
17
+ it { is_expected.to eq(message) }
18
+ end
19
+
6
20
  describe '#compose_message' do
7
21
  subject { described_class.new.send(:compose_message, key, **attributes) }
8
22
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::ValidationErrors do
6
4
  context 'api with rescue_from :all handler' do
7
5
  subject { Class.new(Grape::API) }
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::InvalidAcceptHeader do
6
4
  shared_examples_for 'a valid request' do
7
5
  it 'does return with status 200' do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::InvalidFormatter do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::InvalidResponse do
6
4
  describe '#message' do
7
5
  let(:error) { described_class.new }
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::InvalidVersionerOption do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -10,7 +8,7 @@ describe Grape::Exceptions::InvalidVersionerOption do
10
8
 
11
9
  it 'contains the problem in the message' do
12
10
  expect(error.message).to include(
13
- 'Unknown :using for versioner: headers'
11
+ 'unknown :using for versioner: headers'
14
12
  )
15
13
  end
16
14
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Grape::Exceptions::MissingGroupType do
4
+ describe '#message' do
5
+ subject { described_class.new.message }
6
+
7
+ it { is_expected.to include 'group type is required' }
8
+ end
9
+
10
+ describe 'deprecated Grape::Exceptions::MissingGroupTypeError' do
11
+ subject { Grape::Exceptions::MissingGroupTypeError.new }
12
+
13
+ it 'puts a deprecation warning' do
14
+ expect(Warning).to receive(:warn) do |message|
15
+ expect(message).to include('`Grape::Exceptions::MissingGroupTypeError` is deprecated')
16
+ end
17
+
18
+ subject
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::MissingMimeType do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::MissingOption do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -10,7 +8,7 @@ describe Grape::Exceptions::MissingOption do
10
8
 
11
9
  it 'contains the problem in the message' do
12
10
  expect(error.message).to include(
13
- 'You must specify :path options.'
11
+ 'you must specify :path options'
14
12
  )
15
13
  end
16
14
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::UnknownOptions do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::UnknownValidator do
6
4
  describe '#message' do
7
5
  let(:error) do
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Grape::Exceptions::UnsupportedGroupType do
4
+ subject { described_class.new }
5
+
6
+ describe '#message' do
7
+ subject { described_class.new.message }
8
+
9
+ it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
10
+ end
11
+
12
+ describe 'deprecated Grape::Exceptions::UnsupportedGroupTypeError' do
13
+ subject { Grape::Exceptions::UnsupportedGroupTypeError.new }
14
+
15
+ it 'puts a deprecation warning' do
16
+ expect(Warning).to receive(:warn) do |message|
17
+ expect(message).to include('`Grape::Exceptions::UnsupportedGroupTypeError` is deprecated')
18
+ end
19
+
20
+ subject
21
+ end
22
+ end
23
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  require 'ostruct'
5
4
 
6
5
  describe Grape::Exceptions::ValidationErrors do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Exceptions::Validation do
6
4
  it 'fails when params are missing' do
7
5
  expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
@@ -15,7 +13,7 @@ describe Grape::Exceptions::Validation do
15
13
 
16
14
  context 'when message is a String' do
17
15
  it 'does not store the message_key' do
18
- expect(described_class.new(params: ['id'], message: 'presence').message_key).to eq(nil)
16
+ expect(described_class.new(params: ['id'], message: 'presence').message_key).to be_nil
19
17
  end
20
18
  end
21
19
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Extensions::Hash::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Extensions::Hashie::Mash::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  # see https://github.com/ruby-grape/grape/issues/1348
4
4
 
5
- require 'spec_helper'
6
-
7
5
  def namespace
8
6
  raise
9
7
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Rack::Sendfile do
6
4
  subject do
7
5
  content_object = file_object
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Rack do
6
4
  it 'correctly populates params from a Tempfile' do
7
5
  input = Tempfile.new 'rubbish'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::API do
6
4
  subject do
7
5
  CombinedApi = combined_api
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  require 'base64'
5
4
 
6
5
  describe Grape::Middleware::Auth::Base do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Auth::DSL do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  require 'base64'
6
4
 
7
5
  describe Grape::Middleware::Auth::Strategies do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Base do
6
4
  subject { described_class.new(blank_app) }
7
5
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  require 'grape-entity'
5
4
 
6
5
  describe Grape::Middleware::Error do
@@ -42,6 +41,12 @@ describe Grape::Middleware::Error do
42
41
  expect(last_response.status).to eq(410)
43
42
  end
44
43
 
44
+ it 'sets the status code based on the rack util status code symbol' do
45
+ ErrorSpec::ErrApp.error = { status: :gone }
46
+ get '/'
47
+ expect(last_response.status).to eq(410)
48
+ end
49
+
45
50
  it 'sets the error message appropriately' do
46
51
  ErrorSpec::ErrApp.error = { message: 'Awesome stuff.' }
47
52
  get '/'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Error do
6
4
  let(:exception_app) do
7
5
  Class.new do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Formatter do
6
4
  subject { described_class.new(app) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Globals do
6
4
  subject { described_class.new(blank_app) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Stack do
6
4
  module StackSpec
7
5
  class FooMiddleware; end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Versioner::AcceptVersionHeader do
6
4
  subject { described_class.new(app, **(@options || {})) }
7
5