Skip to content

Commit 3d85058

Browse files
authored
Change Grape::Deprecator's Behavior in test (#2402)
* Grape::Deprecator's Behavior is set to raise in test Fix multiple specs * Add CHANGELOG.md Revert docker-compose.yml
1 parent 40e62bf commit 3d85058

File tree

8 files changed

+20
-35
lines changed

8 files changed

+20
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#2395](https://github.com/ruby-grape/grape/pull/2395): Set `max-age` to 0 when `cookies.delete` - [@ericproulx](https://github.com/ericproulx).
1313
* [#2397](https://github.com/ruby-grape/grape/pull/2397): Add support for ruby 3.3 - [@ericproulx](https://github.com/ericproulx).
1414
* [#2399](https://github.com/ruby-grape/grape/pull/2399): Update `rubocop` to 1.59.0, `rubocop-performance` to 1.20.1 and `rubocop-rspec` to 2.25.0 - [@ericproulx](https://github.com/ericproulx).
15+
* [#2402](https://github.com/ruby-grape/grape/pull/2402): Grape::Deprecations will be raised when running specs - [@ericproulx](https://github.com/ericproulx).
1516
* Your contribution here.
1617

1718
#### Fixes

spec/grape/api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ class DummyFormatClass
12391239
test_file.write file_content
12401240
test_file.rewind
12411241

1242-
subject.get('/file') { file test_file }
1242+
subject.get('/file') { stream test_file }
12431243
get '/file'
12441244
expect(last_response.headers[Rack::CONTENT_LENGTH]).to eq('25')
12451245
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq('text/plain')

spec/grape/dsl/inside_route_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,7 @@ def initialize
209209

210210
it 'emits a warning that this method is deprecated' do
211211
expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/)
212-
213-
subject.file file_path
214-
end
215-
216-
it 'forwards the call to sendfile' do
217212
expect(subject).to receive(:sendfile).with(file_path)
218-
219213
subject.file file_path
220214
end
221215
end
@@ -225,13 +219,7 @@ def initialize
225219

226220
it 'emits a warning that this method is deprecated' do
227221
expect(Grape.deprecator).to receive(:warn).with(/Use stream to use a Stream object/)
228-
229-
subject.file file_object
230-
end
231-
232-
it 'forwards the call to stream' do
233222
expect(subject).to receive(:stream).with(file_object)
234-
235223
subject.file file_object
236224
end
237225
end
@@ -240,13 +228,7 @@ def initialize
240228
describe 'get' do
241229
it 'emits a warning that this method is deprecated' do
242230
expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/)
243-
244-
subject.file
245-
end
246-
247-
it 'fowards call to sendfile' do
248231
expect(subject).to receive(:sendfile)
249-
250232
subject.file
251233
end
252234
end

spec/grape/endpoint_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def memoized
979979
context 'binary' do
980980
before do
981981
subject.get do
982-
file FileStreamer.new(__FILE__)
982+
stream FileStreamer.new(__FILE__)
983983
end
984984
end
985985

spec/grape/validations/params_scope_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def initialize(value)
179179
end
180180

181181
it 'allows the proc to pass validation without checking in except' do
182-
subject.params { requires :numbers, type: Integer, values: { except: -> { [0, 1, 2] } } }
182+
subject.params { requires :numbers, type: Integer, except_values: -> { [0, 1, 2] } }
183183

184184
subject.post('/required') { 'coercion with proc works' }
185185
post '/required', numbers: '10'

spec/grape/validations/validators/values_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def even?(value)
6363
end
6464

6565
params do
66-
requires :type, values: { except: ValuesModel.excepts, except_message: 'value is on exclusions list', message: 'default exclude message' }
66+
requires :type, except_values: { value: ValuesModel.excepts, message: 'value is on exclusions list' }, default: 'default exclude message'
6767
end
6868
get '/exclude/exclude_message'
6969

7070
params do
71-
requires :type, values: { except: -> { ValuesModel.excepts }, except_message: 'value is on exclusions list' }
71+
requires :type, except_values: { value: -> { ValuesModel.excepts }, message: 'value is on exclusions list' }
7272
end
7373
get '/exclude/lambda/exclude_message'
7474

7575
params do
76-
requires :type, values: { except: ValuesModel.excepts, message: 'default exclude message' }
76+
requires :type, except_values: { value: ValuesModel.excepts, message: 'default exclude message' }
7777
end
7878
get '/exclude/fallback_message'
7979
end
@@ -105,7 +105,7 @@ def even?(value)
105105
end
106106

107107
params do
108-
optional :type, values: { except: ValuesModel.excepts }, default: 'valid-type2'
108+
optional :type, except_values: ValuesModel.excepts, default: 'valid-type2'
109109
end
110110
get '/default/except' do
111111
{ type: params[:type] }
@@ -187,42 +187,42 @@ def even?(value)
187187
get '/optional_with_required_values'
188188

189189
params do
190-
requires :type, values: { except: ValuesModel.excepts }
190+
requires :type, except_values: ValuesModel.excepts
191191
end
192192
get '/except/exclusive' do
193193
{ type: params[:type] }
194194
end
195195

196196
params do
197-
requires :type, type: String, values: { except: ValuesModel.excepts }
197+
requires :type, type: String, except_values: ValuesModel.excepts
198198
end
199199
get '/except/exclusive/type' do
200200
{ type: params[:type] }
201201
end
202202

203203
params do
204-
requires :type, values: { except: -> { ValuesModel.excepts } }
204+
requires :type, except_values: ValuesModel.excepts
205205
end
206206
get '/except/exclusive/lambda' do
207207
{ type: params[:type] }
208208
end
209209

210210
params do
211-
requires :type, type: String, values: { except: -> { ValuesModel.excepts } }
211+
requires :type, type: String, except_values: -> { ValuesModel.excepts }
212212
end
213213
get '/except/exclusive/lambda/type' do
214214
{ type: params[:type] }
215215
end
216216

217217
params do
218-
requires :type, type: Integer, values: { except: -> { [3, 4, 5] } }
218+
requires :type, type: Integer, except_values: -> { [3, 4, 5] }
219219
end
220220
get '/except/exclusive/lambda/coercion' do
221221
{ type: params[:type] }
222222
end
223223

224224
params do
225-
requires :type, type: Integer, values: { value: 1..5, except: [3] }
225+
requires :type, type: Integer, values: 1..5, except_values: [3]
226226
end
227227
get '/mixed/value/except' do
228228
{ type: params[:type] }
@@ -234,14 +234,14 @@ def even?(value)
234234
put '/optional_with_array_of_string_values'
235235

236236
params do
237-
requires :type, values: { proc: ->(v) { ValuesModel.include? v } }
237+
requires :type, values: ->(v) { ValuesModel.include? v }
238238
end
239239
get '/proc' do
240240
{ type: params[:type] }
241241
end
242242

243243
params do
244-
requires :type, values: { proc: ->(v) { ValuesModel.include? v }, message: 'failed check' }
244+
requires :type, values: { value: ->(v) { ValuesModel.include? v }, message: 'failed check' }
245245
end
246246
get '/proc/message'
247247

@@ -520,7 +520,7 @@ def even?(value)
520520
it 'raises IncompatibleOptionValues when except contains a value that is not a kind of the type' do
521521
subject = Class.new(Grape::API)
522522
expect do
523-
subject.params { requires :type, values: { except: [10.5, 11] }, type: Integer }
523+
subject.params { requires :type, except_values: [10.5, 11], type: Integer }
524524
end.to raise_error Grape::Exceptions::IncompatibleOptionValues
525525
end
526526

spec/integration/multi_xml/xml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
describe Grape::Xml do
3+
describe Grape::Xml, if: defined?(MultiXml) do
44
it 'uses multi_xml' do
55
expect(described_class).to eq(::MultiXml)
66
end

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
require 'grape'
1212

13+
Grape.deprecator.behavior = :raise
14+
1315
%w[config support].each do |dir|
1416
Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].sort.each do |file|
1517
require file

0 commit comments

Comments
 (0)