本页尚未翻译
下面显示的是英文原文。
subscriber
subscriber(name) opens the record of one subscription: what its handler received and how each delivery settled.
The name is the subscription name the handler mounts under, here "orders".
The record holds every call of the handler in order, with its raw input and its settlement.
Its assertions are those of SubscriberAssertions, such as assert_called_once, with and settled.
Each assertion reads the record at the moment it runs, so a test asserts after the publish that drives the reaction.
A name no handler subscribes to has an empty record, so assert_not_called passes on a misspelled name.
A destination has its own record, published::<T>(name), and an Out slot has out::<M>().
Example
- Macros
- Manual
#[tokio::test]
async fn the_handler_received_the_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let orders = tb.broker::<MemoryBroker>();
orders
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
orders
.subscriber("orders")
.assert_called_once()
.with(&Order { id: 7 })
.settled(HandlerOutcome::ack());
Ok(())
}
#[tokio::test]
async fn the_handler_received_the_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let orders = tb.broker::<MemoryBroker>();
orders
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
orders
.subscriber("orders")
.assert_called_once()
.with(&Order { id: 7 })
.settled(HandlerOutcome::ack());
Ok(())
}