Closed nectariner closed 7 months ago
This is easy. Being a trait object doesn't change the way that you set expectations. Just do it like you would for any other mock object:
let mut puller = MockDataPuller::new();
puller.expect_get_all_boooks()
.times(1)
.returning(|| ...)
Yes but this then has the type Expectation (which doesn't implement the required trait) so can't be provided to the struct containing the trait object
Also I really appreciate the quick reply
Obviously, don't construct AppState from the Expectation. Construct it from the Mock object.
My apologies - I completely misunderstood the docs. I was doing something
let foo = MockFooImplementation::new().expect_my_function().times(1);
let my_struct = S::new(foo);
My bad!
I'm wondering if it's possible to use mock implementation of traits as trait objects owned by a struct. I've been trying this but can't find a way of providing a mock implementation to the struct that has set return values, etc, and then can't make assertions on said trait object because of moves. Any help appreciated - thanks (I've attached some code around what I've been trying)