eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.24k stars 170 forks source link

Reset invocation data without reset the whole mock object #118

Closed FlashBurnGitHub closed 6 years ago

FlashBurnGitHub commented 6 years ago

If I created a mock object I can reset it with the Reset() function, but this is a complete reset.

What I would like to have is a reset of just the invocation data. So that I can do the following:

Mock<SomeInterface> mock;
When(Method(mock,foo)).AlwaysReturn(1);

SomeInterface & i = mock.get();

for(int x = 0; x < 10; x++)
{
    BarClass bar(&i, x);

    bar.foo(20);

    Verify(Method(mock,foo).Using(20));
    Verify(Method(mock,foo)).Once();
    Method(mock,foo).reset();
}

Or is something like that already possible?

eranpeer commented 6 years ago

It is possible, You can use mock.ClearInvocationHistory(). It will do exactly what you want. Enjoy,

On Fri, Nov 10, 2017 at 3:57 AM, FlashBurnGitHub notifications@github.com wrote:

If I created a mock object I can reset it with the Reset() function, but this is a complete reset.

What I would like to have is a reset of just the invocation data. So that I can do the following:

Mock mock;When(Method(mock,foo)).AlwaysReturn(1);

SomeInterface & i = mock.get(); for(int x = 0; x < 10; x++) { BarClass bar(&i, x);

bar.foo(20);

Verify(Method(mock,foo).Using(20));
Verify(Method(mock,foo)).Once();
Method(mock,foo).reset();

}

Or is something like that already possible?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eranpeer/FakeIt/issues/118, or mute the thread https://github.com/notifications/unsubscribe-auth/ACc8glp_5Fg1-lnxvHbtveOTNDgjqdGCks5s1DoMgaJpZM4QZdQA .

-- Eran 1-424-2504000

eranpeer commented 6 years ago

I updated the quick start. It now mentions this option.