Skip to content

Commit

Permalink
Add spec with calling error! helper inside the rescue_from block
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed Jul 3, 2024
1 parent b47d9ad commit 9a551b1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,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, with: custom_error_formatter
subject.get '/exception' do
raise 'rain!'
end
get '/exception'
expect(last_response.body).to eq('message: raining dogs and cats @backtrace')
end
end

it 'rescues all errors and return :json' do
Expand Down

0 comments on commit 9a551b1

Please sign in to comment.