-
Notifications
You must be signed in to change notification settings - Fork 63
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
Support DerefMut for mocks #191
Comments
No. The problem here is that setting expectations requires mutable access to the mock. But Arc does not provide interior mutability. What you want is either to use an let mut mock = MockMyService::new();
mock.expect_get_current()
.times(1)
.returning(|input| {
input * input
});
let arcmock = Arc::new(mock); |
Yup, setting expectations before mocking is the workaround i went with. There is another workaround involving unsafe code. Example:
|
After some searching I found a solution to this: #327 (comment) |
I ran into a bit of a snag testing code involving a lot of smart pointers.
I wanted to do something like this:
I couldn't accomplish this because this code won't compile:
This code:
fails with a compiler error:
I'm wondering if it makes sense to support DerefMut to make testing with smart pointers easier?
The text was updated successfully, but these errors were encountered: