Skip to content

Commit ba81825

Browse files
committed
Stub logging and add stdout logging spec
Suppress the RSpec/AnyInstance cop to allow stubbing of described_class#log_internal_error in the middleware spec (TODO: remove later). Add a new example that asserts an unexpected JSON-RPC internal error is logged to stdout, ensuring the middleware both returns the correct error response and emits an internal error message.
1 parent 476166c commit ba81825

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

spec/jsonrpc/middleware_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@
390390

391391
context 'when processing a JSON-RPC request that causes an unexpected exception' do
392392
it 'returns HTTP 200 OK with a JSON-RPC internal error' do
393+
# TODO: Remove this in the next iteration
394+
# rubocop:disable RSpec/AnyInstance
395+
allow_any_instance_of(described_class).to receive(:log_internal_error)
396+
# rubocop:enable RSpec/AnyInstance
397+
393398
post_jsonrpc_request(
394399
jsonrpc: '2.0',
395400
method: 'explode',
@@ -407,6 +412,16 @@
407412
id: 'req-internal-error'
408413
)
409414
end
415+
416+
it 'logs the internal error to stdout' do
417+
expect do
418+
post_jsonrpc_request(
419+
jsonrpc: '2.0',
420+
method: 'explode',
421+
id: 'req-internal-error'
422+
)
423+
end.to output(/Internal error: Internal JSON-RPC error\./).to_stdout
424+
end
410425
end
411426

412427
# Batch Requests

0 commit comments

Comments
 (0)