Skip to content

async_trait mock times N #381

Answered by asomers
ymwjbxxq asked this question in Questions
May 5, 2022 · 4 comments · 7 replies
Discussion options

You must be logged in to vote

.times(2) is exactly the correct syntax to use if want to expect that a function gets called twice. And if you want to return something different each time, you can use a Sequence, like this:

let mut seq = Sequence::new();
let mut mock = MockAppClient::default();
mock.expect_execute()
    .once()
    .in_sequence(&mut seq)
    .returning(|| something);
mock.expect_execute()
    .once()
    .in_sequence(&mut seq)
    .returning(|| something_else);

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by ymwjbxxq
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ymwjbxxq
Comment options

Comment options

You must be logged in to vote
6 replies
@asomers
Comment options

@ymwjbxxq
Comment options

@asomers
Comment options

@ymwjbxxq
Comment options

@goodgoodwish
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants