Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

assert_not_called

assert_not_called checks that a subscriber's handler never ran.

It passes when the record of that subscription, subscriber(name), is empty. A name no handler subscribes to has an empty record as well, so a misspelled name passes. A positive check on a neighbour guards against that: here assert_called_once on "orders" shows the order did arrive. The handler sends only an order without an id on to "rejected", so a valid order leaves the review subscription untouched. It returns nothing, so it ends a chain. assert_called(n) expects any number of calls.

Example​

#[tokio::test]
async fn a_valid_order_is_not_reviewed() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;

broker.subscriber("orders").assert_called_once();
broker.subscriber("rejected").assert_not_called();
Ok(())
}