@@ -1309,21 +1309,23 @@ def three
1309
1309
1310
1310
context 'CustomError subclass of Grape::Exceptions::Base' do
1311
1311
before do
1312
- class CustomError < Grape ::Exceptions ::Base ; end
1312
+ module ApiSpec
1313
+ class CustomError < Grape ::Exceptions ::Base ; end
1314
+ end
1313
1315
end
1314
1316
1315
1317
it 'does not re-raise exceptions of type Grape::Exceptions::Base' do
1316
- subject . get ( '/custom_exception' ) { fail CustomError }
1318
+ subject . get ( '/custom_exception' ) { fail ApiSpec :: CustomError }
1317
1319
1318
1320
expect { get '/custom_exception' } . not_to raise_error
1319
1321
end
1320
1322
1321
1323
it 'rescues custom grape exceptions' do
1322
- subject . rescue_from CustomError do |e |
1324
+ subject . rescue_from ApiSpec :: CustomError do |e |
1323
1325
rack_response ( 'New Error' , e . status )
1324
1326
end
1325
1327
subject . get '/custom_error' do
1326
- fail CustomError , status : 400 , message : 'Custom Error'
1328
+ fail ApiSpec :: CustomError , status : 400 , message : 'Custom Error'
1327
1329
end
1328
1330
1329
1331
get '/custom_error'
@@ -1474,21 +1476,23 @@ def rescue_arg_error
1474
1476
1475
1477
describe '.rescue_from klass, rescue_subclasses: boolean' do
1476
1478
before do
1477
- module APIErrors
1478
- class ParentError < StandardError ; end
1479
- class ChildError < ParentError ; end
1479
+ module ApiSpec
1480
+ module APIErrors
1481
+ class ParentError < StandardError ; end
1482
+ class ChildError < ParentError ; end
1483
+ end
1480
1484
end
1481
1485
end
1482
1486
1483
1487
it 'rescues error as well as subclass errors with rescue_subclasses option set' do
1484
- subject . rescue_from APIErrors ::ParentError , rescue_subclasses : true do |e |
1488
+ subject . rescue_from ApiSpec :: APIErrors ::ParentError , rescue_subclasses : true do |e |
1485
1489
rack_response ( "rescued from #{ e . class . name } " , 500 )
1486
1490
end
1487
1491
subject . get '/caught_child' do
1488
- fail APIErrors ::ChildError
1492
+ fail ApiSpec :: APIErrors ::ChildError
1489
1493
end
1490
1494
subject . get '/caught_parent' do
1491
- fail APIErrors ::ParentError
1495
+ fail ApiSpec :: APIErrors ::ParentError
1492
1496
end
1493
1497
subject . get '/uncaught_parent' do
1494
1498
fail StandardError
@@ -1502,25 +1506,25 @@ class ChildError < ParentError; end
1502
1506
end
1503
1507
1504
1508
it 'sets rescue_subclasses to true by default' do
1505
- subject . rescue_from APIErrors ::ParentError do |e |
1509
+ subject . rescue_from ApiSpec :: APIErrors ::ParentError do |e |
1506
1510
rack_response ( "rescued from #{ e . class . name } " , 500 )
1507
1511
end
1508
1512
subject . get '/caught_child' do
1509
- fail APIErrors ::ChildError
1513
+ fail ApiSpec :: APIErrors ::ChildError
1510
1514
end
1511
1515
1512
1516
get '/caught_child'
1513
1517
expect ( last_response . status ) . to eql 500
1514
1518
end
1515
1519
1516
1520
it 'does not rescue child errors if rescue_subclasses is false' do
1517
- subject . rescue_from APIErrors ::ParentError , rescue_subclasses : false do |e |
1521
+ subject . rescue_from ApiSpec :: APIErrors ::ParentError , rescue_subclasses : false do |e |
1518
1522
rack_response ( "rescued from #{ e . class . name } " , 500 )
1519
1523
end
1520
1524
subject . get '/uncaught' do
1521
- fail APIErrors ::ChildError
1525
+ fail ApiSpec :: APIErrors ::ChildError
1522
1526
end
1523
- expect { get '/uncaught' } . to raise_error ( APIErrors ::ChildError )
1527
+ expect { get '/uncaught' } . to raise_error ( ApiSpec :: APIErrors ::ChildError )
1524
1528
end
1525
1529
end
1526
1530
@@ -1572,15 +1576,17 @@ class ChildError < ParentError; end
1572
1576
1573
1577
context 'class' do
1574
1578
before :each do
1575
- class CustomErrorFormatter
1576
- def self . call ( message , _backtrace , _options , _env )
1577
- "message: #{ message } @backtrace"
1579
+ module ApiSpec
1580
+ class CustomErrorFormatter
1581
+ def self . call ( message , _backtrace , _options , _env )
1582
+ "message: #{ message } @backtrace"
1583
+ end
1578
1584
end
1579
1585
end
1580
1586
end
1581
1587
it 'returns a custom error format' do
1582
1588
subject . rescue_from :all , backtrace : true
1583
- subject . error_formatter :txt , CustomErrorFormatter
1589
+ subject . error_formatter :txt , ApiSpec :: CustomErrorFormatter
1584
1590
subject . get '/exception' do
1585
1591
fail 'rain!'
1586
1592
end
@@ -1592,16 +1598,18 @@ def self.call(message, _backtrace, _options, _env)
1592
1598
describe 'with' do
1593
1599
context 'class' do
1594
1600
before :each do
1595
- class CustomErrorFormatter
1596
- def self . call ( message , _backtrace , _option , _env )
1597
- "message: #{ message } @backtrace"
1601
+ module ApiSpec
1602
+ class CustomErrorFormatter
1603
+ def self . call ( message , _backtrace , _option , _env )
1604
+ "message: #{ message } @backtrace"
1605
+ end
1598
1606
end
1599
1607
end
1600
1608
end
1601
1609
1602
1610
it 'returns a custom error format' do
1603
1611
subject . rescue_from :all , backtrace : true
1604
- subject . error_formatter :txt , with : CustomErrorFormatter
1612
+ subject . error_formatter :txt , with : ApiSpec :: CustomErrorFormatter
1605
1613
subject . get ( '/exception' ) { fail 'rain!' }
1606
1614
1607
1615
get '/exception'
@@ -1713,15 +1721,17 @@ def self.call(message, _backtrace, _option, _env)
1713
1721
end
1714
1722
end
1715
1723
context 'custom formatter class' do
1716
- module CustomFormatter
1717
- def self . call ( object , _env )
1718
- "{\" custom_formatter\" :\" #{ object [ :some ] } \" }"
1724
+ module ApiSpec
1725
+ module CustomFormatter
1726
+ def self . call ( object , _env )
1727
+ "{\" custom_formatter\" :\" #{ object [ :some ] } \" }"
1728
+ end
1719
1729
end
1720
1730
end
1721
1731
before :each do
1722
1732
subject . content_type :json , 'application/json'
1723
1733
subject . content_type :custom , 'application/custom'
1724
- subject . formatter :custom , CustomFormatter
1734
+ subject . formatter :custom , ApiSpec :: CustomFormatter
1725
1735
subject . get :simple do
1726
1736
{ some : 'hash' }
1727
1737
end
@@ -1765,15 +1775,17 @@ def self.call(object, _env)
1765
1775
end
1766
1776
end
1767
1777
context 'custom parser class' do
1768
- module CustomParser
1769
- def self . call ( object , _env )
1770
- { object . to_sym => object . to_s . reverse }
1778
+ module ApiSpec
1779
+ module CustomParser
1780
+ def self . call ( object , _env )
1781
+ { object . to_sym => object . to_s . reverse }
1782
+ end
1771
1783
end
1772
1784
end
1773
1785
before :each do
1774
1786
subject . content_type :txt , 'text/plain'
1775
1787
subject . content_type :custom , 'text/custom'
1776
- subject . parser :custom , CustomParser
1788
+ subject . parser :custom , ApiSpec :: CustomParser
1777
1789
subject . put :simple do
1778
1790
params [ :simple ]
1779
1791
end
0 commit comments