https://github.com/yowcow/stubby
A stub server and request recorder for testing
https://github.com/yowcow/stubby
cowboy erlang testing
Last synced: 5 months ago
JSON representation
A stub server and request recorder for testing
- Host: GitHub
- URL: https://github.com/yowcow/stubby
- Owner: yowcow
- License: apache-2.0
- Created: 2020-03-17T06:35:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-04T05:59:24.000Z (10 months ago)
- Last Synced: 2025-09-04T07:12:10.550Z (10 months ago)
- Topics: cowboy, erlang, testing
- Language: Erlang
- Size: 40 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stubby
A stub http server and request body recorder.
## Build
rebar3 compile
## How to use
### Configuration
In rebar.config deps, have:
{stubby, {git, "git://github.com/yowcow/stubby", {branch, "master}}}
### Testing
In testing, e.g., common tests, have:
```erlang
init_per_suite(Config) ->
Url = stubby:start(),
[{url, Url} | Config].
end_per_suite(_) ->
ok = stubby:stop().
```
See src/stubby.erl for more options starting up a server.
In a testcase, make a request to stubby URL, then get the most recent request to the **specified** path with:
```erlang
{ok, #{
headers := Headers,
scheme := Scheme,
host := Host,
port := Port,
path := Path,
qs := QueryString,
body := Body
}} = stubby:get_recent("/path/to/endopoint")
```
When no request is recorded yet, this call blocks until the first request is made.
## Endpoints
By default, a booted stubby serves:
- `/`: always responds with status code 200
- `/blackhole/[...]`: always responds with status code 204
Additional cowboy endpoints can be added as a start option:
```erlang
stubby:start([
{"/new/endpoint1", new_endpoint1_handler, []},
{"/new/endpoint2", new_endpoint2_handler, []}
])
```
## See also
-
-
-
-