Permalink
Browse files

Merge pull request #241 from klaaspieter/stub-with-nil-arguments

Convert stub nil arguments to NSNull before adding to params array
  • Loading branch information...
2 parents 88446a2 + 8e52df9 commit 877233dc8da416a98abbe1858b7eff4ce0112d1c Marin Usalj committed Mar 23, 2013
Showing with 18 additions and 0 deletions.
  1. +4 −0 Classes/KWStub.m
  2. +14 −0 Tests/KWStubTest.m
View
@@ -185,6 +185,10 @@ - (BOOL)processInvocation:(NSInvocation *)anInvocation {
const char *argType = [[anInvocation methodSignature] getArgumentTypeAtIndex:i];
if (strcmp(argType, "@?") == 0) arg = [[arg copy] autorelease];
+
+ if (arg == nil)
+ arg = [NSNull null];
+
[args addObject:arg];
}
View
@@ -77,6 +77,20 @@ - (void)testItShouldPerformStubbedBlock {
STAssertEquals(result.callsign, @"Red Leader", @"expected stub to perform given block");
}
+- (void)testItShouldPerformStubbedBlockWhenInvocationHasNilArguments {
+ id subject = [Cruiser cruiser];
+ KWMessagePattern *messagePattern = [KWMessagePattern messagePatternWithSelector:@selector(fighterWithCallsign:)];
+ id stub = [KWStub stubWithMessagePattern:messagePattern block: (id) ^(NSArray *params) {
+ return [[params copy] autorelease];
+ }];
+ NSInvocation *invocation = [NSInvocation invocationWithTarget:subject selector:@selector(fighterWithCallsign:) messageArguments:nil];
+ [stub processInvocation:invocation];
+ id outcome = nil;
+ [invocation getReturnValue:&outcome];
+ NSArray *result = (NSArray *)outcome;
+ STAssertEquals([result objectAtIndex:0], [NSNull null], @"expected stub convert nil arguments to NSNull");
+}
+
- (void)testItShouldRetainValueWhenProcessingInvocationsThatBeginsWithAlloc {
id subject = [Cruiser mock];
id messagePattern = [KWMessagePattern messagePatternWithSelector:@selector(alloc)];

0 comments on commit 877233d

Please sign in to comment.