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: README.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,4 +63,45 @@ The stub files are expected to have this structure:
63
63
}
64
64
```
65
65
66
-
**NOTE:** The operation value must be in lowercase.
66
+
**NOTE:** The operation value must be in lowercase.
67
+
68
+
## Running Specmatic Redis in Tests (with Testcontainers)
69
+
70
+
Use the containerized Specmatic Redis Mock to spin up an ephemeral Redis-like stub for your tests. The snippet below starts the image, mounts your stub data, exposes the port, and **waits until the mock is ready** (detected via a log line) before the test proceeds.
71
+
72
+
```python
73
+
from testcontainers.core.container import DockerContainer
74
+
from testcontainers.core.wait_strategies import LogMessageWaitStrategy
75
+
76
+
77
+
SPECMATIC_REDIS_VERSION="latest"# or a pinned version like "0.9.4"
.waiting_for(LogMessageWaitStrategy(r"Specmatic Redis has started on .*:\d+").with_startup_timeout(10))
88
+
)
89
+
```
90
+
91
+
### What this does
92
+
93
+
***Image**: `specmatic/specmatic-redis:{SPECMATIC_REDIS_VERSION}` – pulls and runs the Specmatic Redis Mock.
94
+
***Command**: `virtualize --host ... --port ... --data ...` – launches Specmatic Redis and points it to your **stub dataset** (files that define responses/fixtures).
95
+
***Port exposure**: `.with_exposed_ports(REDIS_PORT)` – publishes the Redis port to the host so your test client can connect.
96
+
***Volume mapping**: `.with_volume_mapping(STUB_DATA_DIR, STUB_DATA_DIR)` – mounts your local stub directory into the container at the **same** path (keeps file references simple).
97
+
***Readiness check**: `LogMessageWaitStrategy(...)` – blocks test execution until the container logs the **ready** line.
98
+
99
+
### Readiness log pattern
100
+
101
+
The regex `r"Specmatic Redis has started on .*:\d+"` matches a line like:
102
+
103
+
```
104
+
Specmatic Redis has started on 0.0.0.0:6379
105
+
```
106
+
107
+
Ensure `STUB_DATA_DIR` is an **absolute path** and contains your stub files.
0 commit comments