Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Grape::Deprecator's Behavior in test #2402

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [#2395](https://github.com/ruby-grape/grape/pull/2395): Set `max-age` to 0 when `cookies.delete` - [@ericproulx](https://github.com/ericproulx).
* [#2397](https://github.com/ruby-grape/grape/pull/2397): Add support for ruby 3.3 - [@ericproulx](https://github.com/ericproulx).
* [#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).
* [#2402](https://github.com/ruby-grape/grape/pull/2402): Grape::Deprecations will be raised when running specs - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ class DummyFormatClass
test_file.write file_content
test_file.rewind

subject.get('/file') { file test_file }
subject.get('/file') { stream test_file }
get '/file'
expect(last_response.headers[Rack::CONTENT_LENGTH]).to eq('25')
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq('text/plain')
Expand Down
18 changes: 0 additions & 18 deletions spec/grape/dsl/inside_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,7 @@ def initialize

it 'emits a warning that this method is deprecated' do
expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/)

subject.file file_path
end

it 'forwards the call to sendfile' do
expect(subject).to receive(:sendfile).with(file_path)

subject.file file_path
end
end
Expand All @@ -225,13 +219,7 @@ def initialize

it 'emits a warning that this method is deprecated' do
expect(Grape.deprecator).to receive(:warn).with(/Use stream to use a Stream object/)

subject.file file_object
end

it 'forwards the call to stream' do
expect(subject).to receive(:stream).with(file_object)

subject.file file_object
end
end
Expand All @@ -240,13 +228,7 @@ def initialize
describe 'get' do
it 'emits a warning that this method is deprecated' do
expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/)

subject.file
end

it 'fowards call to sendfile' do
expect(subject).to receive(:sendfile)

subject.file
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def memoized
context 'binary' do
before do
subject.get do
file FileStreamer.new(__FILE__)
stream FileStreamer.new(__FILE__)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def initialize(value)
end

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

subject.post('/required') { 'coercion with proc works' }
post '/required', numbers: '10'
Expand Down
26 changes: 13 additions & 13 deletions spec/grape/validations/validators/values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ def even?(value)
end

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

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

params do
requires :type, values: { except: ValuesModel.excepts, message: 'default exclude message' }
requires :type, except_values: { value: ValuesModel.excepts, message: 'default exclude message' }
end
get '/exclude/fallback_message'
end
Expand Down Expand Up @@ -105,7 +105,7 @@ def even?(value)
end

params do
optional :type, values: { except: ValuesModel.excepts }, default: 'valid-type2'
optional :type, except_values: ValuesModel.excepts, default: 'valid-type2'
end
get '/default/except' do
{ type: params[:type] }
Expand Down Expand Up @@ -187,42 +187,42 @@ def even?(value)
get '/optional_with_required_values'

params do
requires :type, values: { except: ValuesModel.excepts }
requires :type, except_values: ValuesModel.excepts
end
get '/except/exclusive' do
{ type: params[:type] }
end

params do
requires :type, type: String, values: { except: ValuesModel.excepts }
requires :type, type: String, except_values: ValuesModel.excepts
end
get '/except/exclusive/type' do
{ type: params[:type] }
end

params do
requires :type, values: { except: -> { ValuesModel.excepts } }
requires :type, except_values: ValuesModel.excepts
end
get '/except/exclusive/lambda' do
{ type: params[:type] }
end

params do
requires :type, type: String, values: { except: -> { ValuesModel.excepts } }
requires :type, type: String, except_values: -> { ValuesModel.excepts }
end
get '/except/exclusive/lambda/type' do
{ type: params[:type] }
end

params do
requires :type, type: Integer, values: { except: -> { [3, 4, 5] } }
requires :type, type: Integer, except_values: -> { [3, 4, 5] }
end
get '/except/exclusive/lambda/coercion' do
{ type: params[:type] }
end

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

params do
requires :type, values: { proc: ->(v) { ValuesModel.include? v } }
requires :type, values: ->(v) { ValuesModel.include? v }
end
get '/proc' do
{ type: params[:type] }
end

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

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

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/multi_xml/xml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Grape::Xml do
describe Grape::Xml, if: defined?(MultiXml) do
it 'uses multi_xml' do
expect(described_class).to eq(::MultiXml)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

require 'grape'

Grape.deprecator.behavior = :raise

%w[config support].each do |dir|
Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].sort.each do |file|
require file
Expand Down