44require 'leopard/message_wrapper'
55
66class FakeMsg
7- attr_reader :data , :responded_payload , :error_args
7+ attr_reader :data , :responded_payload , :error_args , :error_block_called_with
88 attr_accessor :header
99
1010 def initialize ( data , header = { } )
@@ -18,6 +18,11 @@ def respond(payload)
1818
1919 def respond_with_error ( err )
2020 @error_args = [ err ]
21+ return unless block_given?
22+
23+ yielded_error = { }
24+ yield yielded_error
25+ @error_block_called_with = yielded_error
2126 end
2227end
2328
@@ -63,10 +68,23 @@ def respond_with_error(err)
6368 assert_equal [ 'fail' ] , msg . error_args
6469 end
6570
66- it 'coerces exception objects to strings when responding with error' do
71+ it 'passes exception objects through when responding with error' do
6772 err = StandardError . new ( 'broken' )
6873 wrapper . respond_with_error ( err )
6974
70- assert_equal [ 'broken' ] , msg . error_args
75+ assert_equal [ err ] , msg . error_args
76+ end
77+
78+ it 'passes hash payloads through when responding with error' do
79+ err = { 'description' => 'broken' , 'code' => 422 }
80+ wrapper . respond_with_error ( err )
81+
82+ assert_equal [ err ] , msg . error_args
83+ end
84+
85+ it 'forwards blocks when responding with error' do
86+ wrapper . respond_with_error ( code : 422 ) { |error | error [ :code ] = 422 }
87+
88+ assert_equal ( { code : 422 } , msg . error_block_called_with )
7189 end
7290end
0 commit comments