Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate how to use external mocks #27

Closed
nrxus opened this issue Mar 13, 2020 · 2 comments
Closed

Investigate how to use external mocks #27

nrxus opened this issue Mar 13, 2020 · 2 comments

Comments

@nrxus
Copy link
Owner

nrxus commented Mar 13, 2020

It would be great if users of a library could use faux to export mocked versions of their public API.

The problem is that items wrapped by #[cfg(test)] are intentionally not propagated through crates. Which means that any mocks created with the test flag are not lost when the crate is being used as a dependency.

Once we figure out a workaround for this we should document it (perhaps a mini guide?) on how to do it.

@nrxus
Copy link
Owner Author

nrxus commented Apr 17, 2020

My first idea was for something like:

# crate-a
[dependencies]
faux = { version = "0.4", optional = true }

[features]
exposed-mocks = ["faux"]
# crate-b
[dependencies]
crate-a = { version = "1.0" }

[dev-dependencies]
crate-a = { version = "1.0", features = exposed-mocks }

crate-b should now be able to use the mocks created by crate-a as long as the mocks are gated such as:

#[cfg(any(test,exposed-mocks))]
#[faux::create]
pub struct MyPublicStruct { /* fields go here */ }

#[cfg(any(test,exposed-mocks))]
#[faux::methods]
impl MyPublicStruct { /* methods go here */ }

Unfortunately this depends on: rust-lang/cargo#7916

I might have to think of another way... 🤔

@nrxus
Copy link
Owner Author

nrxus commented Oct 5, 2021

a solution to this is explained in: https://nrxus.github.io/faux/guide/exporting-mocks.html

cc: @kungfucop as I believe you were curious about this.

@nrxus nrxus closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant