pub struct Spy<T> { /* private fields */ }Expand description
Spy for tracking method calls with arguments
Implementations§
Source§impl<T> Spy<T>
impl<T> Spy<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new spy without wrapping any object
§Examples
use reinhardt_testkit::mock::Spy;
let spy = Spy::<String>::new();
assert!(spy.inner().is_none());Sourcepub fn wrap(inner: T) -> Self
pub fn wrap(inner: T) -> Self
Create a spy that wraps an existing object
§Examples
use reinhardt_testkit::mock::Spy;
let value = "test".to_string();
let spy = Spy::wrap(value);
assert!(spy.inner().is_some());Sourcepub async fn record_call(&self, args: Vec<Value>)
pub async fn record_call(&self, args: Vec<Value>)
Record a method call with arguments
§Examples
use reinhardt_testkit::mock::Spy;
use serde_json::json;
let spy = Spy::<String>::new();
spy.record_call(vec![json!("arg1"), json!(42)]).await;
assert_eq!(spy.call_count().await, 1);Sourcepub async fn call_count(&self) -> usize
pub async fn call_count(&self) -> usize
Get the total number of recorded calls.
Sourcepub async fn was_called(&self) -> bool
pub async fn was_called(&self) -> bool
Check if the spy was called at least once.
Sourcepub async fn was_called_with(&self, args: Vec<Value>) -> bool
pub async fn was_called_with(&self, args: Vec<Value>) -> bool
Check if the spy was called with specific arguments
§Examples
use reinhardt_testkit::mock::Spy;
use serde_json::json;
let spy = Spy::<String>::new();
spy.record_call(vec![json!("test")]).await;
assert!(spy.was_called_with(vec![json!("test")]).await);
assert!(!spy.was_called_with(vec![json!("other")]).await);Sourcepub async fn get_calls(&self) -> Vec<CallRecord>
pub async fn get_calls(&self) -> Vec<CallRecord>
Get all recorded call records.
Sourcepub async fn last_call_args(&self) -> Option<Vec<Value>>
pub async fn last_call_args(&self) -> Option<Vec<Value>>
Get the arguments from the last recorded call, if any.
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Reset the spy by clearing all call records
§Examples
use reinhardt_testkit::mock::Spy;
use serde_json::json;
let spy = Spy::<String>::new();
spy.record_call(vec![json!("test")]).await;
assert_eq!(spy.call_count().await, 1);
spy.reset().await;
assert_eq!(spy.call_count().await, 0);Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Consume the spy and return the wrapped inner value, if any.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Spy<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Spy<T>
impl<T> Send for Spy<T>where
T: Send,
impl<T> Sync for Spy<T>where
T: Sync,
impl<T> Unpin for Spy<T>where
T: Unpin,
impl<T> UnsafeUnpin for Spy<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for Spy<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().