[−][src]Macro mockiato::mockable
Generates a mock struct from a trait.
Parameters
static_references
Forces values stored in argument matchers to be 'static
. This is used when the mock needs to satisfy
'static
e.g. when downcasting the mocked trait to a concrete implementation using the Any
trait.
There is an example available on how to do this.
use mockiato::mockable; use std::any::Any; #[cfg_attr(test, mockable(static_references))] pub trait Animal: Any { fn make_sound(&self); }
name
Sets a custom name for the mock struct instead of the default.
use mockiato::mockable; #[cfg_attr(test, mockable(name = "CuteAnimalMock"))] trait Animal { fn make_sound(&self); }
remote
Allows mocking of a trait that is declared elsewhere.
The trait declaration will not result in a new trait, since it is only used as a blueprint for generating the mock.
The value for this parameter can be omitted if the trait's name is the same as the imported remote trait.
Examples
With value
use mockiato::mockable; use std::io; #[cfg(test)] #[mockable(remote = "io::Write")] trait Write { fn write(&mut self, buf: &[u8]) -> io::Result<usize>; fn flush(&mut self) -> io::Result<()>; // Methods with a default implementation can be omitted. }
Without value
use mockiato::mockable; use std::io::{self, Write}; #[cfg(test)] #[mockable(remote)] trait Write { fn write(&mut self, buf: &[u8]) -> io::Result<usize>; fn flush(&mut self) -> io::Result<()>; }