grape 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grape might be problematic. Click here for more details.

Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +9 -4
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +166 -0
  6. data/README.md +305 -163
  7. data/Rakefile +30 -33
  8. data/UPGRADING.md +31 -0
  9. data/benchmark/simple.rb +27 -0
  10. data/gemfiles/rack_1.5.2.gemfile +13 -0
  11. data/gemfiles/rails_3.gemfile +2 -2
  12. data/gemfiles/rails_4.gemfile +1 -2
  13. data/grape.gemspec +5 -4
  14. data/lib/grape.rb +9 -5
  15. data/lib/grape/dsl/configuration.rb +5 -2
  16. data/lib/grape/dsl/helpers.rb +8 -3
  17. data/lib/grape/dsl/inside_route.rb +67 -44
  18. data/lib/grape/dsl/parameters.rb +21 -12
  19. data/lib/grape/dsl/request_response.rb +1 -1
  20. data/lib/grape/dsl/routing.rb +3 -4
  21. data/lib/grape/endpoint.rb +63 -28
  22. data/lib/grape/error_formatter/base.rb +6 -6
  23. data/lib/grape/exceptions/base.rb +5 -5
  24. data/lib/grape/exceptions/invalid_version_header.rb +10 -0
  25. data/lib/grape/formatter/serializable_hash.rb +3 -2
  26. data/lib/grape/locale/en.yml +4 -1
  27. data/lib/grape/middleware/auth/base.rb +2 -2
  28. data/lib/grape/middleware/auth/dsl.rb +1 -1
  29. data/lib/grape/middleware/auth/strategies.rb +1 -1
  30. data/lib/grape/middleware/base.rb +7 -4
  31. data/lib/grape/middleware/error.rb +3 -2
  32. data/lib/grape/middleware/filter.rb +1 -1
  33. data/lib/grape/middleware/formatter.rb +47 -44
  34. data/lib/grape/middleware/globals.rb +3 -3
  35. data/lib/grape/middleware/versioner/accept_version_header.rb +5 -7
  36. data/lib/grape/middleware/versioner/header.rb +113 -50
  37. data/lib/grape/middleware/versioner/param.rb +5 -8
  38. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +20 -0
  39. data/lib/grape/middleware/versioner/path.rb +3 -6
  40. data/lib/grape/path.rb +3 -3
  41. data/lib/grape/request.rb +40 -0
  42. data/lib/grape/util/content_types.rb +9 -9
  43. data/lib/grape/util/env.rb +22 -0
  44. data/lib/grape/util/strict_hash_configuration.rb +2 -1
  45. data/lib/grape/validations/attributes_iterator.rb +8 -3
  46. data/lib/grape/validations/params_scope.rb +83 -15
  47. data/lib/grape/validations/types.rb +144 -0
  48. data/lib/grape/validations/types/build_coercer.rb +53 -0
  49. data/lib/grape/validations/types/custom_type_coercer.rb +183 -0
  50. data/lib/grape/validations/types/file.rb +28 -0
  51. data/lib/grape/validations/types/json.rb +65 -0
  52. data/lib/grape/validations/types/multiple_type_coercer.rb +76 -0
  53. data/lib/grape/validations/types/variant_collection_coercer.rb +59 -0
  54. data/lib/grape/validations/types/virtus_collection_patch.rb +16 -0
  55. data/lib/grape/validations/validators/all_or_none.rb +1 -1
  56. data/lib/grape/validations/validators/allow_blank.rb +3 -3
  57. data/lib/grape/validations/validators/base.rb +7 -0
  58. data/lib/grape/validations/validators/coerce.rb +31 -42
  59. data/lib/grape/validations/validators/presence.rb +2 -3
  60. data/lib/grape/validations/validators/regexp.rb +2 -4
  61. data/lib/grape/validations/validators/values.rb +3 -3
  62. data/lib/grape/version.rb +1 -1
  63. data/pkg/grape-0.13.0.gem +0 -0
  64. data/spec/grape/api/custom_validations_spec.rb +5 -4
  65. data/spec/grape/api/deeply_included_options_spec.rb +7 -7
  66. data/spec/grape/api/nested_helpers_spec.rb +4 -2
  67. data/spec/grape/api/shared_helpers_spec.rb +8 -8
  68. data/spec/grape/api_spec.rb +88 -54
  69. data/spec/grape/dsl/configuration_spec.rb +13 -0
  70. data/spec/grape/dsl/helpers_spec.rb +16 -2
  71. data/spec/grape/dsl/inside_route_spec.rb +3 -2
  72. data/spec/grape/dsl/parameters_spec.rb +0 -6
  73. data/spec/grape/dsl/routing_spec.rb +1 -1
  74. data/spec/grape/endpoint_spec.rb +61 -20
  75. data/spec/grape/entity_spec.rb +10 -8
  76. data/spec/grape/exceptions/invalid_accept_header_spec.rb +1 -15
  77. data/spec/grape/integration/rack_spec.rb +3 -2
  78. data/spec/grape/middleware/base_spec.rb +7 -5
  79. data/spec/grape/middleware/error_spec.rb +16 -15
  80. data/spec/grape/middleware/exception_spec.rb +45 -43
  81. data/spec/grape/middleware/formatter_spec.rb +34 -0
  82. data/spec/grape/middleware/versioner/header_spec.rb +79 -47
  83. data/spec/grape/path_spec.rb +10 -10
  84. data/spec/grape/presenters/presenter_spec.rb +2 -2
  85. data/spec/grape/request_spec.rb +100 -0
  86. data/spec/grape/validations/params_scope_spec.rb +11 -9
  87. data/spec/grape/validations/types_spec.rb +95 -0
  88. data/spec/grape/validations/validators/coerce_spec.rb +335 -2
  89. data/spec/grape/validations/validators/values_spec.rb +15 -15
  90. data/spec/grape/validations_spec.rb +53 -24
  91. data/spec/shared/versioning_examples.rb +2 -2
  92. data/spec/spec_helper.rb +0 -1
  93. data/spec/support/versioned_helpers.rb +2 -2
  94. metadata +51 -13
  95. data/.gitignore +0 -46
  96. data/.rspec +0 -2
  97. data/.rubocop.yml +0 -7
  98. data/.rubocop_todo.yml +0 -84
  99. data/.travis.yml +0 -20
  100. data/.yardopts +0 -2
  101. data/lib/grape/http/request.rb +0 -35
  102. data/lib/grape/util/parameter_types.rb +0 -58
  103. data/spec/grape/util/parameter_types_spec.rb +0 -54
@@ -70,6 +70,19 @@ module Grape
70
70
  expect(subject.namespace_setting(:description)).to eq(expected_options)
71
71
  expect(subject.route_setting(:description)).to eq(expected_options)
72
72
  end
73
+
74
+ it 'can be set with options and a block' do
75
+ expect(subject).to receive(:warn).with('[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.')
76
+
77
+ desc_text = 'The description'
78
+ detail_text = 'more details'
79
+ options = { message: 'none' }
80
+ subject.desc desc_text, options do
81
+ detail detail_text
82
+ end
83
+ expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text)
84
+ expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text)
85
+ end
73
86
  end
74
87
  end
75
88
  end
@@ -6,13 +6,20 @@ module Grape
6
6
  class Dummy
7
7
  include Grape::DSL::Helpers
8
8
 
9
- # rubocop:disable TrivialAccessors
10
9
  def self.mod
11
10
  namespace_stackable(:helpers).first
12
11
  end
13
- # rubocop:enable TrivialAccessors
14
12
  end
15
13
  end
14
+
15
+ module BooleanParam
16
+ extend Grape::API::Helpers
17
+
18
+ params :requires_toggle_prm do
19
+ requires :toggle_prm, type: Boolean
20
+ end
21
+ end
22
+
16
23
  describe Helpers do
17
24
  subject { Class.new(HelpersSpec::Dummy) }
18
25
  let(:proc) do
@@ -41,6 +48,13 @@ module Grape
41
48
 
42
49
  expect(subject.mod).to eq mod
43
50
  end
51
+
52
+ context 'with an external file' do
53
+ it 'sets Boolean as a Virtus::Attribute::Boolean' do
54
+ subject.helpers BooleanParam
55
+ expect(subject.mod::Boolean).to eq Virtus::Attribute::Boolean
56
+ end
57
+ end
44
58
  end
45
59
  end
46
60
  end
@@ -343,8 +343,9 @@ module Grape
343
343
  describe '#declared' do
344
344
  # see endpoint_spec.rb#declared for spec coverage
345
345
 
346
- it 'returns an empty hash' do
347
- expect(subject.declared({})).to eq({})
346
+ it 'is not available by default' do
347
+ expect { subject.declared({}) }.to raise_error(
348
+ Grape::DSL::InsideRoute::MethodNotYetAvailable)
348
349
  end
349
350
  end
350
351
  end
@@ -11,31 +11,25 @@ module Grape
11
11
  @validate_attributes = *args
12
12
  end
13
13
 
14
- # rubocop:disable TrivialAccessors
15
14
  def validate_attributes_reader
16
15
  @validate_attributes
17
16
  end
18
- # rubocop:enable TrivialAccessors
19
17
 
20
18
  def push_declared_params(*args)
21
19
  @push_declared_params = args
22
20
  end
23
21
 
24
- # rubocop:disable TrivialAccessors
25
22
  def push_declared_params_reader
26
23
  @push_declared_params
27
24
  end
28
- # rubocop:enable TrivialAccessors
29
25
 
30
26
  def validates(*args)
31
27
  @validates = *args
32
28
  end
33
29
 
34
- # rubocop:disable TrivialAccessors
35
30
  def validates_reader
36
31
  @validates
37
32
  end
38
- # rubocop:enable TrivialAccessors
39
33
  end
40
34
  end
41
35
 
@@ -228,7 +228,7 @@ module Grape
228
228
  end
229
229
 
230
230
  let(:regex) { /(.*)/ }
231
- let!(:options) { { requirements: regex } }
231
+ let!(:options) { { requirements: regex } }
232
232
  it 'nests requirements option under param name' do
233
233
  expect(subject).to receive(:namespace) do |_param, options|
234
234
  expect(options[:requirements][:foo]).to eq regex
@@ -11,15 +11,15 @@ describe Grape::Endpoint do
11
11
  after { Grape::Endpoint.before_each(nil) }
12
12
 
13
13
  it 'should be settable via block' do
14
- block = lambda { |_endpoint| 'noop' }
14
+ block = ->(_endpoint) { 'noop' }
15
15
  Grape::Endpoint.before_each(&block)
16
- expect(Grape::Endpoint.before_each).to eq(block)
16
+ expect(Grape::Endpoint.before_each.first).to eq(block)
17
17
  end
18
18
 
19
19
  it 'should be settable via reference' do
20
- block = lambda { |_endpoint| 'noop' }
20
+ block = ->(_endpoint) { 'noop' }
21
21
  Grape::Endpoint.before_each block
22
- expect(Grape::Endpoint.before_each).to eq(block)
22
+ expect(Grape::Endpoint.before_each.first).to eq(block)
23
23
  end
24
24
 
25
25
  it 'should be able to override a helper' do
@@ -36,6 +36,28 @@ describe Grape::Endpoint do
36
36
  Grape::Endpoint.before_each(nil)
37
37
  expect { get '/' }.to raise_error(NameError)
38
38
  end
39
+
40
+ it 'should be able to stack helper' do
41
+ subject.get('/') do
42
+ authenticate_user!
43
+ current_user
44
+ end
45
+ expect { get '/' }.to raise_error(NameError)
46
+
47
+ Grape::Endpoint.before_each do |endpoint|
48
+ allow(endpoint).to receive(:current_user).and_return('Bob')
49
+ end
50
+
51
+ Grape::Endpoint.before_each do |endpoint|
52
+ allow(endpoint).to receive(:authenticate_user!).and_return(true)
53
+ end
54
+
55
+ get '/'
56
+ expect(last_response.body).to eq('Bob')
57
+
58
+ Grape::Endpoint.before_each(nil)
59
+ expect { get '/' }.to raise_error(NameError)
60
+ end
39
61
  end
40
62
 
41
63
  describe '#initialize' do
@@ -239,6 +261,16 @@ describe Grape::Endpoint do
239
261
  end
240
262
  end
241
263
 
264
+ it 'does not work in a before filter' do
265
+ subject.before do
266
+ declared(params)
267
+ end
268
+ subject.get('/declared') { declared(params) }
269
+
270
+ expect { get('/declared') }.to raise_error(
271
+ Grape::DSL::InsideRoute::MethodNotYetAvailable)
272
+ end
273
+
242
274
  it 'has as many keys as there are declared params' do
243
275
  inner_params = nil
244
276
  subject.get '/declared' do
@@ -742,7 +774,7 @@ describe Grape::Endpoint do
742
774
  get '/hey'
743
775
  expect(last_response.status).to eq 302
744
776
  expect(last_response.headers['Location']).to eq '/ha'
745
- expect(last_response.body).to eq ''
777
+ expect(last_response.body).to eq 'This resource has been moved temporarily to /ha.'
746
778
  end
747
779
 
748
780
  it 'has status code 303 if it is not get request and it is http 1.1' do
@@ -752,6 +784,7 @@ describe Grape::Endpoint do
752
784
  post '/hey', {}, 'HTTP_VERSION' => 'HTTP/1.1'
753
785
  expect(last_response.status).to eq 303
754
786
  expect(last_response.headers['Location']).to eq '/ha'
787
+ expect(last_response.body).to eq 'An alternate resource is located at /ha.'
755
788
  end
756
789
 
757
790
  it 'support permanent redirect' do
@@ -761,7 +794,15 @@ describe Grape::Endpoint do
761
794
  get '/hey'
762
795
  expect(last_response.status).to eq 301
763
796
  expect(last_response.headers['Location']).to eq '/ha'
764
- expect(last_response.body).to eq ''
797
+ expect(last_response.body).to eq 'This resource has been moved permanently to /ha.'
798
+ end
799
+
800
+ it 'allows for an optional redirect body override' do
801
+ subject.get('/hey') do
802
+ redirect '/ha', body: 'test body'
803
+ end
804
+ get '/hey'
805
+ expect(last_response.body).to eq 'test body'
765
806
  end
766
807
  end
767
808
 
@@ -987,38 +1028,38 @@ describe Grape::Endpoint do
987
1028
 
988
1029
  # In order that the events finalized (time each block ended)
989
1030
  expect(@events).to contain_exactly(
990
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1031
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
991
1032
  filters: a_collection_containing_exactly(an_instance_of(Proc)),
992
1033
  type: :before }),
993
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1034
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
994
1035
  filters: [],
995
1036
  type: :before_validation }),
996
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1037
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
997
1038
  filters: [],
998
1039
  type: :after_validation }),
999
- have_attributes(name: 'endpoint_render.grape', payload: { endpoint: an_instance_of(Grape::Endpoint) }),
1000
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1040
+ have_attributes(name: 'endpoint_render.grape', payload: { endpoint: a_kind_of(Grape::Endpoint) }),
1041
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1001
1042
  filters: [],
1002
1043
  type: :after }),
1003
- have_attributes(name: 'endpoint_run.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1004
- env: an_instance_of(Hash) })
1044
+ have_attributes(name: 'endpoint_run.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1045
+ env: an_instance_of(Hash) })
1005
1046
  )
1006
1047
 
1007
1048
  # In order that events were initialized
1008
1049
  expect(@events.sort_by(&:time)).to contain_exactly(
1009
- have_attributes(name: 'endpoint_run.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1010
- env: an_instance_of(Hash) }),
1011
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1050
+ have_attributes(name: 'endpoint_run.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1051
+ env: an_instance_of(Hash) }),
1052
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1012
1053
  filters: a_collection_containing_exactly(an_instance_of(Proc)),
1013
1054
  type: :before }),
1014
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1055
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1015
1056
  filters: [],
1016
1057
  type: :before_validation }),
1017
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1058
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1018
1059
  filters: [],
1019
1060
  type: :after_validation }),
1020
- have_attributes(name: 'endpoint_render.grape', payload: { endpoint: an_instance_of(Grape::Endpoint) }),
1021
- have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: an_instance_of(Grape::Endpoint),
1061
+ have_attributes(name: 'endpoint_render.grape', payload: { endpoint: a_kind_of(Grape::Endpoint) }),
1062
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1022
1063
  filters: [],
1023
1064
  type: :after })
1024
1065
  )
@@ -45,22 +45,24 @@ describe Grape::Entity do
45
45
  entity = Class.new(Grape::Entity)
46
46
  allow(entity).to receive(:represent).and_return('Hiya')
47
47
 
48
- class TestObject
49
- end
48
+ module EntitySpec
49
+ class TestObject
50
+ end
50
51
 
51
- class FakeCollection
52
- def first
53
- TestObject.new
52
+ class FakeCollection
53
+ def first
54
+ TestObject.new
55
+ end
54
56
  end
55
57
  end
56
58
 
57
- subject.represent TestObject, with: entity
59
+ subject.represent EntitySpec::TestObject, with: entity
58
60
  subject.get '/example' do
59
- present [TestObject.new]
61
+ present [EntitySpec::TestObject.new]
60
62
  end
61
63
 
62
64
  subject.get '/example2' do
63
- present FakeCollection.new
65
+ present EntitySpec::FakeCollection.new
64
66
  end
65
67
 
66
68
  get '/example'
@@ -54,13 +54,6 @@ describe Grape::Exceptions::InvalidAcceptHeader do
54
54
  end
55
55
 
56
56
  context 'that receives' do
57
- context 'an invalid version in the request' do
58
- before do
59
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77',
60
- 'CONTENT_TYPE' => 'application/json'
61
- end
62
- it_should_behave_like 'a rescued request'
63
- end
64
57
  context 'an invalid vendor in the request' do
65
58
  before do
66
59
  get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
@@ -128,13 +121,6 @@ describe Grape::Exceptions::InvalidAcceptHeader do
128
121
  end
129
122
 
130
123
  context 'that receives' do
131
- context 'an invalid version in the request' do
132
- before do
133
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77',
134
- 'CONTENT_TYPE' => 'application/json'
135
- end
136
- it_should_behave_like 'a rescued request'
137
- end
138
124
  context 'an invalid vendor in the request' do
139
125
  before do
140
126
  get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
@@ -318,7 +304,7 @@ describe Grape::Exceptions::InvalidAcceptHeader do
318
304
 
319
305
  context 'that receives' do
320
306
  context 'an invalid version in the request' do
321
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
307
+ before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
322
308
  it_should_behave_like 'a cascaded request'
323
309
  end
324
310
  context 'an invalid vendor in the request' do
@@ -20,8 +20,9 @@ describe Rack do
20
20
  env = Rack::MockRequest.env_for('/', options)
21
21
 
22
22
  unless RUBY_PLATFORM == 'java'
23
- major, minor, release = Rack.release.split('.').map(&:to_i)
24
- pending 'Rack 1.5.3 or 1.6.1 required' unless major >= 1 && ((minor == 5 && release >= 3) || (minor >= 6))
23
+ major, minor, patch = Rack.release.split('.').map(&:to_i)
24
+ patch ||= 0 # rack <= 1.5.2 does not specify patch version
25
+ pending 'Rack 1.5.3 or 1.6.1 required' unless major >= 1 && ((minor == 5 && patch >= 3) || (minor >= 6))
25
26
  end
26
27
 
27
28
  expect(JSON.parse(app.call(env)[2].body.first)['params_keys']).to match_array('test')
@@ -82,18 +82,20 @@ describe Grape::Middleware::Base do
82
82
  end
83
83
 
84
84
  context 'defaults' do
85
- class ExampleWare < Grape::Middleware::Base
86
- def default_options
87
- { monkey: true }
85
+ module BaseSpec
86
+ class ExampleWare < Grape::Middleware::Base
87
+ def default_options
88
+ { monkey: true }
89
+ end
88
90
  end
89
91
  end
90
92
 
91
93
  it 'persists the default options' do
92
- expect(ExampleWare.new(blank_app).options[:monkey]).to be true
94
+ expect(BaseSpec::ExampleWare.new(blank_app).options[:monkey]).to be true
93
95
  end
94
96
 
95
97
  it 'overrides default options when provided' do
96
- expect(ExampleWare.new(blank_app, monkey: false).options[:monkey]).to be false
98
+ expect(BaseSpec::ExampleWare.new(blank_app, monkey: false).options[:monkey]).to be false
97
99
  end
98
100
  end
99
101
  end
@@ -11,14 +11,15 @@ describe Grape::Middleware::Error do
11
11
  'static text'
12
12
  end
13
13
  end
14
- end
15
- class ErrApp
16
- class << self
17
- attr_accessor :error
18
- attr_accessor :format
19
14
 
20
- def call(_env)
21
- throw :error, error
15
+ class ErrApp
16
+ class << self
17
+ attr_accessor :error
18
+ attr_accessor :format
19
+
20
+ def call(_env)
21
+ throw :error, error
22
+ end
22
23
  end
23
24
  end
24
25
  end
@@ -28,32 +29,32 @@ describe Grape::Middleware::Error do
28
29
  Rack::Builder.app do
29
30
  use Spec::Support::EndpointFaker
30
31
  use Grape::Middleware::Error, opts
31
- run ErrApp
32
+ run ErrorSpec::ErrApp
32
33
  end
33
34
  end
34
35
 
35
- let(:options) { { default_message: 'Aww, hamburgers.' } }
36
+ let(:options) { { default_message: 'Aww, hamburgers.' } }
36
37
 
37
38
  it 'sets the status code appropriately' do
38
- ErrApp.error = { status: 410 }
39
+ ErrorSpec::ErrApp.error = { status: 410 }
39
40
  get '/'
40
41
  expect(last_response.status).to eq(410)
41
42
  end
42
43
 
43
44
  it 'sets the error message appropriately' do
44
- ErrApp.error = { message: 'Awesome stuff.' }
45
+ ErrorSpec::ErrApp.error = { message: 'Awesome stuff.' }
45
46
  get '/'
46
47
  expect(last_response.body).to eq('Awesome stuff.')
47
48
  end
48
49
 
49
50
  it 'defaults to a 500 status' do
50
- ErrApp.error = {}
51
+ ErrorSpec::ErrApp.error = {}
51
52
  get '/'
52
53
  expect(last_response.status).to eq(500)
53
54
  end
54
55
 
55
56
  it 'has a default message' do
56
- ErrApp.error = {}
57
+ ErrorSpec::ErrApp.error = {}
57
58
  get '/'
58
59
  expect(last_response.body).to eq('Aww, hamburgers.')
59
60
  end
@@ -61,14 +62,14 @@ describe Grape::Middleware::Error do
61
62
  context 'with http code' do
62
63
  let(:options) { { default_message: 'Aww, hamburgers.' } }
63
64
  it 'adds the status code if wanted' do
64
- ErrApp.error = { message: { code: 200 } }
65
+ ErrorSpec::ErrApp.error = { message: { code: 200 } }
65
66
  get '/'
66
67
 
67
68
  expect(last_response.body).to eq({ code: 200 }.to_json)
68
69
  end
69
70
 
70
71
  it 'presents an error message' do
71
- ErrApp.error = { message: { code: 200, with: ErrorSpec::ErrorEntity } }
72
+ ErrorSpec::ErrApp.error = { message: { code: 200, with: ErrorSpec::ErrorEntity } }
72
73
  get '/'
73
74
 
74
75
  expect(last_response.body).to eq({ code: 200, static: 'static text' }.to_json)