mockall icon indicating copy to clipboard operation
mockall copied to clipboard

"Mock" is prefixed even when using `mock!`

Open garrettmaring opened this issue 4 years ago • 2 comments

in the automock! documentation it is suggested to use mock! if "the autogenerated “MockFoo” name isn’t acceptable, and you want to choose your own name for the mock structure."

however, when I use mock! { pub MyStruct {} } i received an undeclared variable when trying to read MyStruct but it works when I change my import to use MockMyStruct.

how can I determine the name of the mocked structure using mock!?

garrettmaring avatar Sep 05 '21 01:09 garrettmaring

You're right; you can't. mock! is designed to allow as closely as possible copy/pasting the original struct's definition. That's why it prefixes the "Mock". Do you have a good suggestion for a syntax for an enhancement that would disable the automatic prefix?

asomers avatar Sep 05 '21 02:09 asomers

hm, is mock!(prefix = "") or mock!(disable-prefix) the simplest possibilities?

i'm also reminded of serde's renaming #[serde(rename = "MyRename")] which could lead to something similar that might go inside mock! above the struct definition.

garrettmaring avatar Sep 05 '21 03:09 garrettmaring