I was trying to do:
[[[mockQuestion stub] andReturnValue:YES] shouldNegate];
[[[mockQuestion stub] andReturnValue:123] randomNumberWithLimit];
But that gave me this warning/error “incompatible integer pointer conversion sending ‘BOOL’ (aka ‘signed char’) to parameter of type ‘NSValue *'”
The only way I could figure out to get around it was to do:
BOOL boolValue = YES;
int num = 123;
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(boolValue)] shouldNegate];
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(num)] randomNumberWithLimit];
But that makes my test code seem so overly verbose.. Is there a way to do this all inline without having to set variables?
You can use a literal style that looks like
(type){value}. This is commonly used to create struct literals but works for basic datatypes too. The important aspect here is that this type of literal creates a temporary that can be addressed. This means you can write your code like