0

In a test with OCMock, I must assert that no call is made to the setState: selector. However, I can make no assumption about the other calls that are made to the object.

Because any other call can be made, I have to (or do I?) use a niceMockForClass: instead of mockForClass:

How can I then make sure that no call is made to setState: ? The code roughly looks like this:

- (void)testNoCallIsMadeToSetStateOnReset
{
    self.downloader = [OCMock niceMockForClass:[Downloader class]];

    [[self.downloader expectZero] setState:OCMOCK_ANY]; // <- how to do this?

    // do some stuff
    [self.downloader verify]
}
aspyct
  • 3,625
  • 7
  • 36
  • 61

1 Answers1

1

You can use [[yourMock reject] setState:OCMOCK_ANY];

e1985
  • 6,239
  • 1
  • 24
  • 39
  • Almost there, but... the setState: method's argument is an enum. `typedef enum { ... } DownloaderState`. It doesn't seem to work with OCMOCK_ANY. Is there a workaround for this? – aspyct Oct 14 '13 at 10:48
  • Sorry but I don't know how to do that, there is nothing like OCMOCK_ANY_VALUE. Maybe someone else can help on this... As an alternative, either you can use a normal mock(not nice) and stub the methods that are posible to be called on your mock, or reject setState: to all possible parameters. – e1985 Oct 14 '13 at 12:45
  • Another workaround is to use a real object instead of a mock, and check directly the value of the state property. Before the code to test you can set it to a value that does not exist in the enum and after check if the value is still the same... You could also create a partial mock of this object if you want to stub/expect something... – e1985 Oct 14 '13 at 12:55
  • That could be a good solution. I'll look into this. Many thanks :) – aspyct Oct 14 '13 at 13:01
  • 1
    Use `[[[yourMock reject] ignoringNonObjectArgs] setState:0]` . The ignoringNonObjectArgs is a new feature which basically says assume all non-object args effectively have an OCMOCK_ANY on them, so the values you use for the mock call don't matter. – Carl Lindberg Oct 21 '13 at 01:01