Skip to content

Commit

Permalink
Add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed Jul 3, 2024
1 parent 3f01d03 commit 2eabc9b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ class ChildError < ParentError; end
end
end

describe '.error_format' do
describe '.error_formatter' do
it 'rescues all errors and return :txt' do
subject.rescue_from :all
subject.format :txt
Expand Down Expand Up @@ -2460,6 +2460,18 @@ def self.call(message, _backtrace, _options, _env, _original_exception)
get '/exception'
expect(last_response.body).to eq('message: rain! @backtrace')
end

it 'returns a modified error with a custom error format' do
subject.rescue_from :all, backtrace: true do |e|
error!("raining dogs and cats", 418, {}, e.backtrace, e)
end
subject.error_formatter :txt, ApiSpec::CustomErrorFormatter
subject.get '/exception' do
raise 'rain!'
end
get '/exception'
expect(last_response.body).to eq('message: raining dogs and cats @backtrace')
end
end

describe 'with' do
Expand Down

0 comments on commit 2eabc9b

Please sign in to comment.