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

Mocking traits #20

Open
nrxus opened this issue Jan 22, 2020 · 1 comment
Open

Mocking traits #20

nrxus opened this issue Jan 22, 2020 · 1 comment

Comments

@nrxus
Copy link
Owner

nrxus commented Jan 22, 2020

While there exist other libraries already capable of doing this, it might be nice to also provide that functionality here to not force the user to find yet another mocking framework on top of faux.

@nrxus
Copy link
Owner Author

nrxus commented Apr 3, 2021

I took a quick look at this and I would love to implement something that looks like:

#[faux::create]
trait MyTrait { /* some methods */ }

#[test]
fn test() {
    let mock = MyTrait::faux();
}

This however seems to only be possible if MyTrait is object safe which has a lot of limitations that I am not sure are desired.

Another issue I am having is that I don't know how should generics and associated items should work.

  • Should all generics in a trait also go into the created struct?
  • Should associated types in a trait be generics of the struct or should the user have to specify them as a macro argument?
  • How should associated constants (which are not allowed if we require object safety) be declared?
  • Should associated functions be mockable? They are not in structs since that would require some sort of "global" mock store, but for a trait maybe we could?

Since I don't really have a use case for this, I always mock structs, I don't really know what the desired behavior for some of these may be. I also don't know what limitations are acceptable and which ones would make the feature useless.

In short, this is theoretically feasible but I would love help understanding the requirements before I implement something that isn't valuable for those that need it.

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