nrxus / faux

Struct mocking library for Rust
https://nrxus.github.io/faux/
MIT License
415 stars 14 forks source link

Multiple calls mocks. #2

Closed nrxus closed 4 years ago

nrxus commented 4 years ago

Currently when we set up a mock:

unsafe { when!(my_mock.some_method).then(|_| { /* do things */} )

It sets up a one time mock, which means that after the mock is invoked, next time it runs the code will panic saying that no mock was set.

This library should support mocks that are set up once and run multiple times, either a set number of times, or forever.

nrxus commented 4 years ago

Calling a mock multiple times can be achieved by either:

I am unsure which one of these two approaches is the most limiting to an user.

nrxus commented 4 years ago

Another thing to keep in mind, do we want to keep the FnOnce without clone behavior for the edge cases where the mock needs to move data that cannot be cloned? Or should that just be removed until I come across an scenario that actually needs that kind of mock

TedDriggs commented 4 years ago

Could you add a new method, .always(...) which had the Clone constraint?

nrxus commented 4 years ago

Yes, that's a possibility.

The biggest two things stopping me from implementing this are:

At some point even without feedback I will move on and just do whatever feels right at the moment but for now I am trying to see if something comes up that guides my decision.

TedDriggs commented 4 years ago

I'd suggest that an active when mock overrules a standing always mock.

audunhalland commented 4 years ago

+1 for multiple calls. Currently cannot switch to faux exclusively because of this.

nrxus commented 4 years ago

I am prioritizing this as my next thing to tackle after https://github.com/nrxus/faux/issues/10

nrxus commented 4 years ago

fixed in: https://github.com/nrxus/faux/commit/a2fc133fa0a2079feef8a42cc4bbea564a51c0b0

I will close this after doing a new release... which should be soon.

nrxus commented 4 years ago

v0.0.4 is released with this feature :tada: