Skip to content

Commit

Permalink
Add spec to demonstrate usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mscrivo committed Jun 29, 2023
1 parent 0bc6579 commit 6fa44b1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/grape/exceptions/body_parse_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,46 @@ def app
end
end

context 'api with rescue_from :grape_exceptions handler with block' do
subject { Class.new(Grape::API) }

before do
subject.rescue_from :grape_exceptions do |e|
rack_response "Custom Error Contents, Original Message: #{e.message}", 400
end

subject.params do
requires :beer
end

subject.post '/beer' do
'beer received'
end
end

def app
subject
end

context 'with content_type json' do
it 'returns body parsing error message' do
post '/beer', 'test', 'CONTENT_TYPE' => 'application/json'
expect(last_response.status).to eq 400
expect(last_response.body).to include 'message body does not match declared format'
expect(last_response.body).to include 'Custom Error Contents, Original Message'
end
end

context 'with content_type xml' do
it 'returns body parsing error message' do
post '/beer', 'test', 'CONTENT_TYPE' => 'application/xml'
expect(last_response.status).to eq 400
expect(last_response.body).to include 'message body does not match declared format'
expect(last_response.body).to include 'Custom Error Contents, Original Message'
end
end
end

context 'api without a rescue handler' do
subject { Class.new(Grape::API) }

Expand Down

0 comments on commit 6fa44b1

Please sign in to comment.