-
Notifications
You must be signed in to change notification settings - Fork 20
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
Mock traits #35
Comments
That's an interesting feature to add in the future. For now what about existing mocking tools? Do they miss anything? |
No existing mock object library does everything. This is the best comparison of them. BTW, I'm working on a library of my own, but I haven't released it yet. |
That's very interesting, great job with bring it all together and thank you for including Mocktopus! To be honest I was trying to create a tool for mocking traits too but found obstacles and didn't put enough time into it. I've dropped idea of building a mock struct based on trait definition passed to a macro very quickly, because it causes a difficult problem when trait inherits from other trait. The mock struct should implement it as well, because it won't compile, but macro has no idea how to do it. I was trying to construct a fake trait object with https://doc.rust-lang.org/std/raw/struct.TraitObject.html. I think that this approach could give just right amount of power. Unfortunately I couldn't find a way to match fn pointers and trait methods. It's even harder because Rust optimizes away multiple functions delegating to each other and sometimes the same fn pointer shows up in vtable multiple times. |
Mocktopus is very handy for mocking free functions. But when mocking structs, it requires a real copy of the struct to be instantiated. That's not always easy or possible in test environments. That's why most mocking libraries work in terms of traits instead. It would be great if Mocktopus could provide a macro that would instantiate a trait and mock all of its methods. Something like this:
The
mock
macro could expand to this:The text was updated successfully, but these errors were encountered: