You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/testing/readme.md
+36-2Lines changed: 36 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,45 @@ This guide explains how to test `Async::HTTP` clients and servers without depend
4
4
5
5
Real network services make tests slower and less deterministic. Prefer one of these approaches:
6
6
7
+
- Use [`sus-fixtures-protocol-http`](https://socketry.github.io/sus-fixtures-protocol-http/guides/getting-started/) to exercise HTTP middleware directly without a client or server.
7
8
- Use `sus-fixtures-async-http` to run an application with a managed local server and client.
8
9
- Use ruby:`Async::HTTP::Mock::Endpoint` when testing a client that expects to connect to a particular remote endpoint.
9
-
- Use a small fake client when the HTTP protocol behavior itself is not under test.
10
10
11
-
## Testing an HTTP Application
11
+
## Testing Middleware Directly
12
+
13
+
When a test only needs to construct requests and inspect responses, `sus-fixtures-protocol-http` can call `Protocol::HTTP` middleware in-process without starting a client or server. Add the fixture to your test dependencies:
14
+
15
+
~~~bash
16
+
$ bundle add sus --group test
17
+
$ bundle add sus-fixtures-protocol-http --group test
18
+
~~~
19
+
20
+
Include `MiddlewareContext` and provide the middleware under test:
The fixture closes the final request, response, and middleware after each test. Use `sus-fixtures-async-http` when the test needs a real client/server exchange.
44
+
45
+
## Testing with a Client and Server
12
46
13
47
The `ServerContext` fixture manages an ephemeral listening endpoint, server task, and connected client. Add the fixture to your test dependencies:
0 commit comments