Skip to content

Commit 54e823b

Browse files
dm1trydblock
authored andcommitted
add failing spec for .rescue_from regression
see #1957
1 parent 951d6d0 commit 54e823b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spec/grape/api_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,26 @@ def foo
19421942
expect { get '/unrescued' }.to raise_error(RuntimeError, 'beefcake')
19431943
end
19441944

1945+
it 'mimics default ruby "rescue" handler' do
1946+
# The exception is matched to the rescue starting at the top, and matches only once
1947+
1948+
subject.rescue_from ArgumentError do |e|
1949+
error!(e, 402)
1950+
end
1951+
subject.rescue_from StandardError do |e|
1952+
error!(e, 401)
1953+
end
1954+
1955+
subject.get('/child_of_standard_error') { raise ArgumentError }
1956+
subject.get('/standard_error') { raise StandardError }
1957+
1958+
get '/child_of_standard_error'
1959+
expect(last_response.status).to eql 402
1960+
1961+
get '/standard_error'
1962+
expect(last_response.status).to eql 401
1963+
end
1964+
19451965
context 'CustomError subclass of Grape::Exceptions::Base' do
19461966
before do
19471967
module ApiSpec

0 commit comments

Comments
 (0)