@@ -1593,13 +1593,23 @@ class CommunicationError < StandardError; end
1593
1593
def rescue_arg_error
1594
1594
error! ( '500 ArgumentError' , 500 )
1595
1595
end
1596
+
1597
+ def rescue_no_method_error
1598
+ error! ( '500 NoMethodError' , 500 )
1599
+ end
1596
1600
end
1597
1601
subject . rescue_from ArgumentError , with : :rescue_arg_error
1598
- subject . get ( '/rescue_method' ) { fail ArgumentError }
1602
+ subject . rescue_from NoMethodError , with : :rescue_no_method_error
1603
+ subject . get ( '/rescue_arg_error' ) { fail ArgumentError }
1604
+ subject . get ( '/rescue_no_method_error' ) { fail NoMethodError }
1599
1605
1600
- get '/rescue_method '
1606
+ get '/rescue_arg_error '
1601
1607
expect ( last_response . status ) . to eq ( 500 )
1602
1608
expect ( last_response . body ) . to eq ( '500 ArgumentError' )
1609
+
1610
+ get '/rescue_no_method_error'
1611
+ expect ( last_response . status ) . to eq ( 500 )
1612
+ expect ( last_response . body ) . to eq ( '500 NoMethodError' )
1603
1613
end
1604
1614
1605
1615
it 'aborts if the specified method name does not exist' do
@@ -1608,6 +1618,31 @@ def rescue_arg_error
1608
1618
1609
1619
expect { get '/rescue_method' } . to raise_error ( NoMethodError , 'undefined method `not_exist_method\'' )
1610
1620
end
1621
+
1622
+ it 'correctly chooses exception handler if :all handler is specified' do
1623
+ subject . helpers do
1624
+ def rescue_arg_error
1625
+ error! ( '500 ArgumentError' , 500 )
1626
+ end
1627
+
1628
+ def rescue_all_errors
1629
+ error! ( '500 AnotherError' , 500 )
1630
+ end
1631
+ end
1632
+
1633
+ subject . rescue_from ArgumentError , with : :rescue_arg_error
1634
+ subject . rescue_from :all , with : :rescue_all_errors
1635
+ subject . get ( '/argument_error' ) { fail ArgumentError }
1636
+ subject . get ( '/another_error' ) { fail NoMethodError }
1637
+
1638
+ get '/argument_error'
1639
+ expect ( last_response . status ) . to eq ( 500 )
1640
+ expect ( last_response . body ) . to eq ( '500 ArgumentError' )
1641
+
1642
+ get '/another_error'
1643
+ expect ( last_response . status ) . to eq ( 500 )
1644
+ expect ( last_response . body ) . to eq ( '500 AnotherError' )
1645
+ end
1611
1646
end
1612
1647
1613
1648
describe '.rescue_from klass, rescue_subclasses: boolean' do
0 commit comments