by shem » 16 Aug 2012, 10:03
Here are a couple of new ideas here, because this is a big hole in the testing framework in my opinion:
(1) Extending OCMockRecorder to have a more generalized method of ignoring matching any argument besides the current mechanism that only works with objects (and has an interesting implementation for pointers...)
- (id)ignoresArgAtIndex:(NSUInteger)index; //(or maybe just restrict it to non-object 'values' only, which may look like 'ignoresValueArgAtIndex')
And then in the 'matchesInvocation' method, you could just check if that particular index had been registered as needing to be ignored, and if so, ignoring that particular argument. Seems pretty simple, and technically still fits the recorder mantra.
(2) Another way of achieving this could be by just providing a 'alwaysMatchesInvocation:^(NSInvocation invocation /* or potentially just providing the array of parameters */) {...}' (assuming the arg types and arg count is the same as the method signature) bit on the recorder, and then leaving the assertion of what's allowed and disallowed explicitly to the definition in the block. The default behavior could be to fallback to the original matching behavior if the matcher fails. It's a bit heavy handed, but could work -- very similar to the 'doBlock' variant, except this one would be evaluated to determine if the invocation should match.
Here are a couple of new ideas here, because this is a big hole in the testing framework in my opinion:
(1) Extending OCMockRecorder to have a more generalized method of ignoring matching any argument besides the current mechanism that only works with objects (and has an interesting implementation for pointers...)
- (id)ignoresArgAtIndex:(NSUInteger)index; //(or maybe just restrict it to non-object 'values' only, which may look like 'ignoresValueArgAtIndex')
And then in the 'matchesInvocation' method, you could just check if that particular index had been registered as needing to be ignored, and if so, ignoring that particular argument. Seems pretty simple, and technically still fits the recorder mantra.
(2) Another way of achieving this could be by just providing a 'alwaysMatchesInvocation:^(NSInvocation invocation /* or potentially just providing the array of parameters */) {...}' (assuming the arg types and arg count is the same as the method signature) bit on the recorder, and then leaving the assertion of what's allowed and disallowed explicitly to the definition in the block. The default behavior could be to fallback to the original matching behavior if the matcher fails. It's a bit heavy handed, but could work -- very similar to the 'doBlock' variant, except this one would be evaluated to determine if the invocation should match.