pub struct MockActorSequence { /* private fields */ }
Expand description
A mock for a sequence of messages sent to the actor Example:
struct FakeActor;
impl Actor for FakeActor {
type Context = actix::Context<Self>;
}
struct Msg1;
struct Msg2;
impl Message for Msg1 {
type Result = i32;
}
impl Message for Msg2 {
type Result = bool;
}
#[actix_rt::main]
async fn main() {
let mock_actor = MockActorSequence::new()
.msg(|_m: &Msg1| 5) // you can access the message sent.
.msg::<Msg2, _>(|_m| true) // alternate syntax to specify the message type
.build::<FakeActor>();
assert_eq!(mock_actor.send(Msg1).await.unwrap(), 5);
assert_eq!(mock_actor.send(Msg2).await.unwrap(), true);
}
Implementations§
Source§impl MockActorSequence
impl MockActorSequence
pub fn new() -> Self
Sourcepub fn msg<Msg, Cb>(self, cb: Cb) -> Self
pub fn msg<Msg, Cb>(self, cb: Cb) -> Self
Add another message to be expected, and return the result of the callback. The type of the message is checked at runtime against the expectation, and the message itself is passed to the callback so that it can be used to build the result
§Panics
Panics when the received message is not the expected type. This is appropriate for testing since a panic will be a test failure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MockActorSequence
impl !RefUnwindSafe for MockActorSequence
impl !Send for MockActorSequence
impl !Sync for MockActorSequence
impl Unpin for MockActorSequence
impl !UnwindSafe for MockActorSequence
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