Struct noir::HttpResponse
[−]
[src]
pub struct HttpResponse<E: HttpEndpoint> { // some fields omitted }
A mocked HTTP response that is being provided to a testable API.
Methods
impl<E: HttpEndpoint> HttpResponse<E>
[src]
fn with_status(self, status_code: StatusCode) -> Self
Sets the response status.
fn with_headers(self, headers: Vec<HttpHeader>) -> Self
Sets additional headers to be send with the response.
Use the headers![...]
macro to easily create a vector containing
concrete types of the hyper::Header
trait for use with this method.
fn with_header<H: Header + HeaderFormat>(self, header: H) -> Self
Sets one additional header to be send with the response.
fn with_query(self, query: HttpQueryString) -> Self
Sets the query string of the response's path.
This will override any existing query string previously set or derived from the request's path.
fn with_body<S: Into<HttpBody>>(self, body: S) -> Self
Sets the response body.
Also sets the Content-Type
header of the response based on the type
of the body
argument.
The set Content-Type
can be overridden via HttpResponse::with_header
.
fn with_error(self, error: Error) -> Self
Sets a low level IO error to be returned once the response is read.
fn with_options(self, options: Options) -> Self
Sets the response's configuration options.
This allows to change or override the default response behaviour.
fn expected_header<H: Header + HeaderFormat>(self, header: H) -> Self
Sets one additional header that should be present on the request to the response.
Test Failure
If the header is either missing from the request or its value does not match the expected one.
fn unexpected_header<H: Header + HeaderFormat>(self) -> Self
Sets one additional header that should be absent from the request made to the response.
Test Failure
If the header is present on the request.
fn expected_headers(self, headers: Vec<HttpHeader>) -> Self
Sets additional headers that should be present on the request to the response.
Use the headers![...]
macro to easily create a vector containing
concrete types of the hyper::Header
trait for use with this method.
Test Failure
If one or more of the headers are either missing from the request or their values differ from the expected ones.
fn expected_body<S: Into<HttpBody>>(self, body: S) -> Self
Sets the expected request body for the response.
The expected and the actual body are compared based on the MIME type of the request.
text/*
These Compared as strings, if no other character encoding is set in the request's MIME type, UTF-8 will be used as the default.
application/json
JSON objects are deep compared, but additional keys on request objects are ignored.
This allows for simpler and more fine grained assertions against JSON requests.
All other mime types
These are compared on a byte by byte basis.
Test Failure
If the actual request body does not match the expected one.
Test Failure Examples
From test_provided_response_with_expected_body_raw_mismatch
(Collapse)
From test_provided_response_with_expected_body_text_mismatch_diff_added
(Expand)
From test_provided_response_with_expected_body_json_mismatch
(Expand)
From test_provided_response_with_expected_body_form_mismatch
(Expand)
fn expected_exact_body<S: Into<HttpBody>>(self, body: S) -> Self
Sets the expected request body for the response, exact version.
This method is based on HttpRequest::expected_body()
but performs
additional comparison based on the mime type of the request:
application/json
In contrast to HttpResponse::expected_body()
additional keys on
request objects are compared and will fail the test.
All other mime types
See HttpResponse::expected_body()
.
Test Failure
If the actual request body does not match the expected one.
fn dump(self) -> Self
Dumps the request headers and body for this response.
Test Failure
Always.
Test Failure Examples
From test_provided_response_dump_raw
(Collapse)
From test_provided_response_dump_text
(Expand)
From test_provided_response_dump_json
(Expand)
Trait Implementations
impl<E: HttpEndpoint> MockResponse for HttpResponse<E>
[src]
fn matches(&self, request: &Box<MockRequest>) -> bool
Compare the response against any type implementing MockRequest
and return true
if they belong together. Read more
fn respond(&mut self, request: Box<MockRequest>) -> Result<Vec<u8>, Error>
Called when the implementation of MockResponse::matches
return true
. Read more
fn validate(&mut self, response_index: usize, request_index: usize) -> Vec<String>
If the response has a matching MockRequest
, compare the two and return a vector of error messages listing any differences. Read more
fn validate_header(&self, error_count: usize) -> String
Return a header for use with the formatted error values returned by MockResponse::validate()
. Read more