feat: Add spy! macro and #[autospy] attribute#682
Open
exoego wants to merge 2 commits intoasomers:masterfrom
Open
feat: Add spy! macro and #[autospy] attribute#682exoego wants to merge 2 commits intoasomers:masterfrom
exoego wants to merge 2 commits intoasomers:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #567
Adds
spy!procedural macro (analogous tomock!)#[autospy]attribute macro (analogous to#[automock]) supports both traits and struct impl blocksreal.into_spy()helper which is a shorthand forSpyFoo::new(real)Design decisions:
MockItemStruct/MockFunction/MockTraitwith aGenerateModeflag. This keeps code duplication low but ties spy behavior to mock internals.SpyFoo<T: MyTrait>accepts any type that implements the trait. Struct spies use a concrete type directly because inherent methods have no trait to use as a bound.impl Traitreturn-types (including plainasync fn) are not supported. Because Mockall converts these toPin<Box<dyn Trait>>, which causes a type mismatch when calling the real implementation.#[async_trait]works because it does this conversion before mockall processes the trait. This is documented as a known limitation.calling_real()is needed for verified delegation. Unlike Java (Mockito)/Ruby(RSpec) spy frameworks that record all calls and let you check them after the fact, Mockall requires expectations to be set up before the call. So, users must explicitly usecalling_real()when they want to both delegate and verify.