diff --git a/src/app.rs b/src/app.rs index 2355c24..b5fb8d2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -181,6 +181,8 @@ impl App< } } +/// TestApp is a testing framework for ratpack applications. Given an App, it can issue mock +/// requests to it without standing up a typical web server. #[derive(Clone)] pub struct TestApp { app: App, @@ -188,10 +190,13 @@ pub struct TestApp TestApp { + /// Construct a new tested application. pub fn new(app: App) -> Self { Self { app, headers: None } } + /// with_headers applies the headers to any following request, and acts as an alternative + /// constructor. pub fn with_headers(&self, headers: http::HeaderMap) -> Self { Self { app: self.app.clone(), @@ -199,6 +204,7 @@ impl Test } } + /// dispatch a request to the application, this allows for maximum flexibility. pub async fn dispatch(&self, req: Request) -> Response { self.app.dispatch(req).await.unwrap() } @@ -215,6 +221,7 @@ impl Test req } + /// Perform a GET request against the path. pub async fn get(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); @@ -224,6 +231,7 @@ impl Test .unwrap() } + /// Perform a POST request against the path. pub async fn post(&self, path: &str, body: Body) -> Response { let req = self.populate_headers(Request::builder()); @@ -233,6 +241,7 @@ impl Test .unwrap() } + /// Perform a DELETE request against the path. pub async fn delete(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -246,6 +255,7 @@ impl Test .unwrap() } + /// Perform a PUT request against the path. pub async fn put(&self, path: &str, body: Body) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -254,6 +264,7 @@ impl Test .unwrap() } + /// Perform an OPTIONS request against the path. pub async fn options(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -267,6 +278,7 @@ impl Test .unwrap() } + /// Perform a PATCH request against the path. pub async fn patch(&self, path: &str, body: Body) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -275,6 +287,7 @@ impl Test .unwrap() } + /// Perform a HEAD request against the path. pub async fn head(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -288,6 +301,7 @@ impl Test .unwrap() } + /// Perform a TRACE request against the path. pub async fn trace(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); self.app @@ -301,6 +315,7 @@ impl Test .unwrap() } + /// Perform a CONNECT request against the path. pub async fn connect(&self, path: &str) -> Response { let req = self.populate_headers(Request::builder()); self.app diff --git a/src/lib.rs b/src/lib.rs index c01c73f..f7c3017 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -/// Application/Server-level management and routing configuration; outermost functionality. +/// Application/Server-level management and routing configuration and testing support; outermost functionality. pub mod app; /// Handler construction and prototypes pub mod handler;