Permalink
Browse files

Convert stub nil arguments to NSNull before adding to params array

  • Loading branch information...
1 parent 88446a2 commit 8e52df91a1884624a9790a394ed3e2efd37aea64 Klaas Pieter Annema committed Mar 20, 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 8e52df9

Please sign in to comment.