Struct mockito::Mock [] [src]

pub struct Mock { /* fields omitted */ }

Stores information about a mocked request. Should be initialized via mockito::mock().

Methods

impl Mock
[src]

Allows matching a particular request header when responding with a mock.

When matching a request, the field letter case is ignored.

Example

use mockito::mock;

mock("GET", "/").match_header("content-type", "application/json");

Like most other Mock methods, it allows chanining:

Example

use mockito::mock;

mock("GET", "/")
  .match_header("content-type", "application/json")
  .match_header("authorization", "password");

Sets the status code of the mock response. The default status code is 200.

Example

use mockito::mock;

mock("GET", "/").with_status(201);

Sets a header of the mock response.

Example

use mockito::mock;

mock("GET", "/").with_header("content-type", "application/json");

Sets the body of the mock response. Its Content-Length is handled automatically.

Example

use mockito::mock;

mock("GET", "/").with_body("hello world");

Sets the body of the mock response from the contents of a file stored under path. Its Content-Length is handled automatically.

Example

use mockito::mock;

mock("GET", "/").with_body_from_file("tests/files/simple.http");

Registers the mock to the server - your mock will be served only after calling this method.

Example

use mockito::mock;

mock("GET", "/").with_body("hello world").create();

Registers the mock to the server, executes the passed closure and removes the mock afterwards.

NOTE: During the closure lifetime, the mock might still be available to seperate threads.

Example

use std::thread::{sleep};
use std::time::Duration;
use mockito::mock;

mock("GET", "/").with_body("hello world").create_for(|| {
  // This mock will only be available for the next 1 second
  sleep(Duration::new(1, 0));
});

Removes the current mock from the server.

Example

use mockito::mock;

let mut mock = mock("GET", "/");
mock.with_body("hello world").create();

// stuff

mock.remove();

Trait Implementations

impl PartialEq for Mock
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Mock
[src]

Formats the value using the given formatter.