Trait noir::MockResponse [] [src]

pub trait MockResponse: Send {
    fn matches(&self, &Box<MockRequest>) -> bool;
    fn respond(&mut self, Box<MockRequest>) -> MockRequestResponse;
    fn validate(&mut self, response_index: usize, request_index: usize) -> Vec<String>;
    fn validate_header(&self, error_count: usize) -> String;
}

A trait for implementation of a response provided to a concrete type of MockRequest.

Required Methods

fn matches(&self, &Box<MockRequest>) -> bool

Compare the response against any type implementing MockRequest and return true if they belong together.

Any implementation should try to downcast the boxed value to its concrete type and - if the downcast succeeds - compare the custom properties of the request and response.

Requests will try to match all the responses in the order these were provided to the test and will call MockResponse::respond() for the first match.

Responses which should only match a single request need to always return false once MockResponse::respond() was called.

fn respond(&mut self, Box<MockRequest>) -> MockRequestResponse

Called when the implementation of MockResponse::matches return true.

Should return a Result with either the response body or a std::io::Error.

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.

Test Failure

If the return vector contains any error messages.

fn validate_header(&self, error_count: usize) -> String

Return a header for use with the formatted error values returned by MockResponse::validate().

Implementors