Verify a method was never called with OCMock 3
Asked Answered
U

3

9

How do I verify a method is never called with OCMock 3?

I was thinking something like this:

XCTAssertThrows(OCMVerify([_restDataSource getSomeStuff:[OCMArg any]]));

But it seems like OCMVerify doesn't throw for a fail.

Upbraiding answered 25/2, 2015 at 22:55 Comment(0)
E
10

Please see first point under http://ocmock.org/reference/#advanced-topics

Note that reject at this point in time requires the old-style syntax and it must be called before the method may be invoked, ie.

// first set up the mock
[[mock reject] methodThatShouldNotBeCalled]
// then call method that should not result in the call

For a glimpse on what's planned, see https://github.com/erikdoe/ocmock/issues/109

Elana answered 27/2, 2015 at 12:56 Comment(1)
Thanks for a nice tool Erik.Upbraiding
S
1

As I answered here, starting from version 3.3 OCMock has OCMReject macro.

Sandrasandro answered 27/4, 2016 at 11:58 Comment(0)
D
0

I failed miserably at getting the reject-method to work so my solution was to simply stub the method-not-to-be-called(notifyChange: in example below) with throwing an exception whenever it is called.

// Set up the mock.
id<TSModelObserver> observer = OCMProtocolMock(@protocol(TSModelObserver));

// Stub the forbidden method call with throwing an exception.    
[OCMStub([observer notifyChange:model]) andThrow:[NSException new]];
Donoghue answered 14/10, 2015 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.