Trait httpmock::MockRefExt [−][src]
The MockRefExt trait extends the MockRef structure with some additional functionality, that is usually not required.
Required methods
fn new(id: usize, mock_server: &'a MockServer) -> MockRef<'a>
[src]
Creates a new MockRef instance that references an already existing mock on a MockServer. This functionality is usually not required. You can use it if for you need to recreate MockRef instances .
id
- The ID of the existing mock ot the MockServer.mock_server
- The MockServer to which the MockRef instance will reference.
Example
use httpmock::{MockServer, MockRef, MockRefExt}; use isahc::get; // Arrange let server = MockServer::start(); let mock_ref = server.mock(|when, then| { when.path("/test"); then.status(202); }); // Store away the mock ID for later usage and drop the MockRef instance. let mock_id = mock_ref.id(); drop(mock_ref); // Act: Send the HTTP request let response = get(server.url("/test")).unwrap(); // Create a new MockRef instance that references the earlier mock at the MockServer. let mock_ref = MockRef::new(mock_id, &server); // Use the recreated MockRef as usual. mock_ref.assert(); assert_eq!(response.status(), 202);
Refer to [Issue 26
][https://github.com/alexliesenfeld/httpmock/issues/26] for more
information.
fn id(&self) -> usize
[src]
Returns the ID that the mock was assigned to on the MockServer.