Skip to content

Commit

Permalink
v0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
nrxus committed Feb 24, 2022
1 parent 85693fd commit 12a7f59
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## v0.1.6
* 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 implement `Clone` and then use
`faux::when!(my_struct.clone()).then(..)` as you would any other
method.
* [test](/tests/clone.rs)

## v0.1.5
* Be more explicit about stubbing vs mocking
* Fixed issue where faux was requiring MSRV 1.54.0 because of doctests
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faux"
version = "0.1.5"
version = "0.1.6"
authors = ["Andres <[email protected]>"]
license = "MIT"
description = "A library to mock structs"
Expand All @@ -11,7 +11,7 @@ keywords = ["mock", "mocking", "test", "testing", "faux"]
readme = "README.md"

[dependencies]
faux_macros = { path = "faux_macros", version = "0.1.5" }
faux_macros = { path = "faux_macros", version = "0.1.6" }
paste = "1.0.4"

[dev-dependencies]
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,28 @@ attributes should be gated to `#[cfg(test)]`.**

`faux` also provides easy-to-use argument matchers.

## Interactions With Other Proc Macros
## Interaction with `#[derive(...)]` and auto-traits.

`faux` mocks will auto implement `Send` and `Sync` if the real
instance also implements it. Using `#[derive(...)]` for `Clone`,
`Debug`, and `Default` will also work as expected. Other derivable
traits are not supported as they are about data (e.g., `Eq`, or
`Hash`) but `faux` is about mocking behavior not data. Deriving traits
that are not part of the standard library is also not currently
supported. An escape hatch for this is to manually write the `impl`
for that trait. If you believe there is a derivable trait that `faux`
should support please file an issue explaining your use case.

`Clone` is a bit of a special case in that it does not duplicate the
stubs but instead shares them with the cloned instance. If this is not
the desired behavior for cloning mocks you may instead implement
`Clone` manually and do normal method stubbing
(`faux::when!(my_struct.clone()).then_return(/* something */)`). Note
that for the cases of exhaustable stubs (e.g.,
`faux::when!(my_struct.foo()).once()`) if either instance calls for
the stub that will count as exhausting the stub as they are shared.

## Interactions with other proc macros

While `faux` makes no guarantees that it will work with other macro
libraries, it should "just" work. There are some caveats, however. For
Expand Down
4 changes: 2 additions & 2 deletions faux_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faux_macros"
version = "0.1.5"
version = "0.1.6"
authors = ["Andres <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,7 +13,7 @@ keywords = ["mock", "mocking", "test", "testing", "faux"]
syn = { version = "1.0.58", features = ["full", "extra-traits"] }
quote = "1.0.8"
proc-macro2 = "1.0.24"
darling = "0.12.0"
darling = "0.13"

[dev-dependencies]
faux = { path = "../" }
Expand Down
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
//!
//! At a high level, `faux` is split into:
//!
//! * [`#[create]`](create): transforms a struct into a mockable equivalent
//! * [`#[methods]`](methods): transforms the methods in an `impl` block into
//! their mockable equivalents
//! * [`when!`]: initializes a method stub by returning a [`When`]. Passing optional argument matchers restricts which arguments will invoke the stub.
//! * [`When`]: lets you stub a method's return value or implementation
//! * [`#[create]`](create): transforms a struct into a mockable
//! equivalent
//! * [`#[methods]`](methods): transforms the methods in an `impl`
//! block into their mockable equivalents
//! * [`when!`]: initializes a method stub by returning a
//! [`When`]. Passing optional argument matchers restricts which
//! arguments will invoke the stub.
//! * [`When`]: lets you stub a method's return value or
//! implementation
//!
//! # Getting Started
//!
Expand Down Expand Up @@ -239,6 +243,8 @@
//! * Generic struct methods
//! * Methods with pointer self types (e.g., `self: Rc<Self>`)
//! * Methods in external modules
//! * Support for `Debug`, `Default`, `Clone`, `Send`, and `Sync`
//! derive/auto traits.
//!
//! `faux` also provides easy-to-use argument matchers.
//!
Expand Down

0 comments on commit 12a7f59

Please sign in to comment.