Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is it possible to mock functions that belong to external modules? #219

Closed
rbruggem opened this issue Oct 13, 2020 · 3 comments
Closed
Labels
question Usage question

Comments

@rbruggem
Copy link

rbruggem commented Oct 13, 2020

For instance, tokio::time::delay_for.

@asomers-ax
Copy link

Sure. You can use automock like this:

#[cfg(test)]
#[automock]
mod time {
    fn delay_for();
}

#[cfg(test)]
use mock_time as time;
#[cfg(not(test))]
use time;

@asomers asomers added the question Usage question label Oct 18, 2020
@asomers
Copy link
Owner

asomers commented Oct 18, 2020

I'm going to close this issue, because I think you're satisfied by that answer. But BTW, the [#double] attribute might help you, too.
https://docs.rs/mockall_double/0.1.0/mockall_double/attr.double.html

@jinq0123
Copy link

#[cfg(test)]
#[automock]
mod time {
    fn delay_for();
}

should be

fn delay_for() {}

else

error: custom attribute panicked
   = help: message: Unsupported item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usage question
Projects
None yet
Development

No branches or pull requests

4 participants