@@ -4,6 +4,7 @@ class CustomStatusError < StandardError;end
44class CustomTitleError < StandardError ; end
55class MessageTrueError < StandardError ; end
66class MessageProcError < StandardError ; end
7+ class MetaProcError < StandardError ; end
78class LogFalseError < StandardError ; end
89class CustomHandlerError < StandardError ; end
910class SpecialPostError < StandardError ; end
@@ -21,6 +22,7 @@ class ApplicationController < ActionController::Base
2122 register_exception CustomTitleError , title : 'My Title'
2223 register_exception MessageTrueError , message : true
2324 register_exception MessageProcError , message : -> ( e ) { e . class . name . upcase }
25+ register_exception MetaProcError , meta : -> ( e ) { { class_name : e . class . name . upcase } }
2426 register_exception LogFalseError , log : false
2527 register_exception CustomHandlerError , handler : CustomErrorHandler
2628
@@ -82,6 +84,11 @@ def standard_detail
8284 end
8385
8486 context 'when the error is registered' do
87+ it 'is registered' do
88+ registered = controller . registered_exception? ( CustomStatusError . new )
89+ expect ( registered ) . to eq true
90+ end
91+
8592 context 'with custom status' do
8693 before do
8794 raises ( CustomStatusError , 'some message' )
@@ -128,6 +135,17 @@ def standard_detail
128135 end
129136 end
130137
138+ context 'with meta as proc' do
139+ before do
140+ raises ( MetaProcError , 'some_error' )
141+ end
142+
143+ it 'shows custom error detail' do
144+ get :index
145+ expect ( error [ 'meta' ] ) . to match ( 'class_name' => 'METAPROCERROR' )
146+ end
147+ end
148+
131149 context 'with log: false' do
132150 before do
133151 expect ( Rails . logger ) . to_not receive ( :error )
0 commit comments