add JRPC::Transport::Test to use in tests#26
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new in-process transport double JRPC::Transport::Test to the library (not autoloaded), so user code that talks to a JSON-RPC server via SimpleClient/SharedClient can be unit-tested without standing up a real server. The new transport combines the use cases previously served by the spec-only TransportDouble (for SimpleClient) and FakeSharedTransport (for SharedClient), exposing a high-level handler API (on('method') { ... }) plus a low-level escape hatch (push_response / push_raise, strict: false) for malformed/orphan/id-mismatch scenarios. A Unix socketpair backs the transport so SharedClient's IO.select loop works correctly.
Changes:
- New
lib/jrpc/transport/test.rbimplementing theTransport::Basecontract with handlers, recordings, raw scripting, and FD lifecycle (closekeeps FDs alive;shutdownand a GC finalizer release them). - New
spec/transport/test_spec.rbexercising the transport with bothSimpleClientandSharedClient, including strict-mode, error mapping,fail_connect, and notification recording. - Documentation in
README.md(new "Testing" section) and aCHANGELOG.mdentry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lib/jrpc/transport/test.rb |
New library transport double with handler API, raw escape hatch, socketpair-backed IO.select support, and shutdown/finalizer FD cleanup. |
spec/transport/test_spec.rb |
New spec covering the transport against SimpleClient and SharedClient. |
README.md |
New "Testing" section documenting JRPC::Transport::Test, handlers, strict mode, raw API, and shutdown. |
CHANGELOG.md |
Changelog entry under "New" for the test transport. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
closes #10