- Add support for mocking methods with generic parameters
- Bump MSRV as v1.63
- Fix issue where methods that returned a type with a name that contains the name of the mocked struct would fail to compile.
- Properly mark MSRV as v1.58.
- This was accidentally bumped in a previous release. A test for
MSRV has been added to CI to prevent this happening in the future by
accident. Note that
faux
considers MSRV bumps as non-breaking but we still try to keep it to a minimum and only to older rust versions.
- This was accidentally bumped in a previous release. A test for
MSRV has been added to CI to prevent this happening in the future by
accident. Note that
- Allow
#[faux::methods]
to wrap functions that return the mocked struct wrapped inRc
,Arc
,Box
,Result
, orOption
.
- Fix issue where a type with
::
could not be used as a generic argument in animpl
signature. - Support multiple
impl
blocks for the same struct in the same module- This relies on the uniqueness of a uuid v4 which is technically not guaranteed to be unique but pretty darn likely to be.
- Bump MSRV to 1.56
- Don't change the parameter names in mocked methods if their pattern is just an identifier. This is useful so that the rust-analyzer overlay hints still show the actual parameter names.
- Panics when adding mocks to a cloned mock.
- The goal (apart from optimizations) is to reduce magical action-at-a-distance problems caused by having two mock instances add new stubs that affect each other. The goal behind allowing cloning in the previous release was so that the code under test can call for clone without the test needing to be aware of those implementation details, not for the test itself to be able to clone.
- Support cloning mocks using
#[derive(Clone)]
- If a mockable struct is annotated with
#[derive(Clone)]
, cloning a mock instance of that struct will create a new mock instance that shares any existing and future stubs between the two mock instances. If this is not your desired behavior for mock cloning you can still manually implementClone
and then usefaux::when!(my_struct.clone()).then(..)
as you would any other method. - test
- If a mockable struct is annotated with
- Be more explicit about stubbing vs mocking
- Fixed issue where faux was requiring MSRV 1.54.0 because of doctests
- Make sure
faux
is using the latest version offaux_macros
- Support mocking methods with arguments of type:
&impl Trait
- Fixes a bug that made tests either fail or segfault in release mode
- Adds support for methods to return a
Self
instance.- Before only associated functions (e.g.,
Self::new
) would work - This allows you to mock a custom implementation of
Clone
- test
- Before only associated functions (e.g.,
- No api changes
- Allow autoderiving
Default
on structs tagged by#[create]
- Only allowed if the real instance implements
Default
- Only allowed if the real instance implements
- Add
pattern!
andfrom_fn!
macros to create matchers out of patterns and functions respectively. - Hide the internal structure of
Eq
,Any
, andEqAgainst
.- Their respective methods now return
impl ArgMatcher<Arg>
to help against breaking changes in the future.
- Their respective methods now return
Eq
,EqAgainst
, andAny
are now all internal tofaux
. This will help prevent against breaking changes in the future.
when!
allows for argument matching- requires the arguments to implement
Debug
- test
- requires the arguments to implement
When
has a newwith_args
method to specify argument matchers.- The preferred way to set argument matchers is using
when!
which proxies to this method - test
- The preferred way to set argument matchers is using
- Handle concurrent calls to different method calls in the same mock instance
- Support for mocking the same method multiple times by doing a latest that matches approach
When
has more generic arguments- This is technically a breaking change but unlikely to affect you.
- Do not rely on the type signature of
When
as it is subject to change.
WhenOnce
->when::Once
then*
methods have been renamed to be more consisten with Rust patterns- The safe
then
method now allows for non-static inputs. then_do
was removed as the improvement onthen
made it unnecessary.
then
was renamed:then_unchecked
then_return
was renamed:then_unchecked_return
safe_then
was renamed:then
safe_then_return
was renamed:then_return
then_do
was removed
- Allow mocking of methods with a
Pin<P>
receiver.- This is limited to
P
s that are not nested:Rc<Self>
,Box<Self>
,Arc<Self>
,&Self
, and&mut Self>
. - Setting
self_type
toPin
for thecreate
andmethods
macro is still not supported. - tests
- This is limited to
- Minimum rust version changed to 1.45
- Removes
proc-macro-hack
dependency.- Starting on rust 1.45, function-like proc macros are allowed in statement expressions
- Allow autoderiving
Clone
.- It will panic when trying to clone a mocked instance but work as expected on real instances
- test
- Added
then_do
- It explicitly avoids letting the user look at the input parameters such that it can be safe to use on methods with non-static arguments
- Added
then_return
- Allows users to easily and safely mock the return value of methods without using a closure
- Minimum rust version changed to 1.45
- Suppport
impl
arguments in mocked methods
- Mocks can now be called an infinite number of times
- Trait implementations may now be mocked
- tests
- This is a very MVP release for the feature. A limitation that may be lifted in the future is that you may not have two methods with the same name, even if one is through a trait implementation.
- Better macro error messages
- PR. Thanks a lot @TedDriggs!
self: Box<Self>
,self: Rc<Self>
, andself: Arc<Self>
are now allowed in methods inside an impl blocked tagged by#[methods]
. See the tests for what is possible with arbitrary self types.
- Specifying a path in
#[methods]
has changed from:#[methods(path::to::mod)]
to#[methods(path = "path::to::mod")]
. This is done to allow further current and future arguments to be passed to the attribute. - The default behavior for mocks has changed to be active for multiple
calls. As a result, now mocks only accept
FnMut
closures which cannot have environment data moved into. If your mocks used to depend on moving data into the closure for the mock, you can use theonce
method onWhen
to go back to the old behavior.
- Async methods may now be mocked
- Mocked structs may now contain generics
- Mocked impl blocks may now contain a path
- Paths that contain
super
orcrate
have to use thefaux::methods(path)
syntax. - tests
- Paths that contain
- Made mocked structs respect Sync+Send+Debug.
- This allows mocking structs that are enforced to be Sync/Send/Debug. This has a performance impact as we now used Mutex rather than RefCell for interor mutability. This is unideal and will be addressed in a future release.
- All closures used for mocking methods must now implement Send. This means that all of its captures variables need to implement Send. This is unideal but needed for now to be able to mock things like Rocket's request guards.
- Initial alpha release