dredd-hooks-rust • Dredd HTTP API testing integration for Rust
This package contains a Rust Dredd hook handler which provides a bridge between the Dredd API Testing Framework and Rust environment to ease implementation of testing hooks provided by Dredd. Write Dredd hooks in Rust to glue together API Blueprint with your Rust project.
Not sure what these Dredd Hooks are? Read the Dredd documentation on them.
The following are a few examples of what hooks can be used for:
- loading db fixtures
- cleanup after test step or steps
- handling authentication and sessions
- passing data between transactions (saving state from responses to stash)
- modifying request generated from blueprint
- changing generated expectations
- setting custom expectations
- debugging via logging stuff
Installation
Global installation
If you don't have it already, install the Dredd CLI via npm:
In order for the Dredd CLI to be able to interface with your test binaries, you need to have the dredd-hooks-rust
binary installed, which you can get by running:
Per-project setup
To start testing your Rust project with Dredd, just add dredd-hooks
to your Cargo.toml
:
[]
= "0.2.1"
Or if you have cargo-edit installed you can just run this on the command line:
Usage example
Following this is a short example showcasing Dredd tests running against an iron
server.
The name of the project in this example is assumed to be dredd-rust-test
:
test.apib
# My Api
## GET /message
+ Response 200 (text/plain)
Hello World!
main.rs
:
extern crate iron;
extern crate router;
extern crate dredd_hooks;
use *;
use Router;
use ;
// HTTP endpoint
Run the command:
&&
You should now see Dredd trying to run the tests against the binary that was just compiled, but actually skipping the single test it tries to run because we told Dredd to do so via a before
hook.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgements
Thank you to:
- The developers behind goodman for providing a good example of how to integrate Dredd with a compiled language.