From 21fa9822af6ba81847a35590714c6e490e46ba61 Mon Sep 17 00:00:00 2001 From: dm1try Date: Thu, 9 Jan 2020 04:00:35 +0300 Subject: [PATCH] add failing spec for .rescue_from regression see #1957 --- spec/grape/api_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index a199e33d05..4ff1cd4fb4 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -1942,6 +1942,26 @@ def foo expect { get '/unrescued' }.to raise_error(RuntimeError, 'beefcake') end + it 'mimics default ruby "rescue" handler' do + # The exception is matched to the rescue starting at the top, and matches only once + + subject.rescue_from ArgumentError do |e| + error!(e, 402) + end + subject.rescue_from StandardError do |e| + error!(e, 401) + end + + subject.get('/child_of_standard_error') { raise ArgumentError } + subject.get('/standart_error') { raise StandardError } + + get '/child_of_standard_error' + expect(last_response.status).to eql 402 + + get '/standard_error' + expect(last_response.status).to eql 401 + end + context 'CustomError subclass of Grape::Exceptions::Base' do before do module ApiSpec