mohkhan
mohkhan

Reputation: 12315

OCMock expect and return gives signature error

I have a method of the followng signature;

- (NSInteger) getFirstVisitTimeStamp;

When I use OCMock to mock and return a value, the test fails with the below error.

[[[[YSNYI13NMockingTest mockedYI13N] expect] andReturnValue:@(12345)] getFirstVisitTimeStamp];

Error:

file:///%3Cunknown%3E: test failure:
failed: Return value does not match method signature; signature declares 'q' but value is 'i'.

Can anyone help ?

Upvotes: 6

Views: 2287

Answers (2)

mspensieri
mspensieri

Reputation: 3521

On 64-bit devices, NSInteger is declared as long, but the value you are returning is being typed as int. Try forcing your value to a long by adding l after the number:

[[[[YSNYI13NMockingTest mockedYI13N] expect] andReturnValue:@(12345l)] getFirstVisitTimeStamp];

Upvotes: 9

shortstuffsushi
shortstuffsushi

Reputation: 2330

As @michaels hinted at in the comments, and after searching a bit further into your error message, this appears to be related to an open bug in OCMock.

It seems using OCMOCK_VALUE(...) might work for you instead.

Upvotes: 3

Related Questions