Skip to content

Commit

Permalink
valueForKey: can be stubbed
Browse files Browse the repository at this point in the history
  • Loading branch information
eraserhd committed Dec 11, 2012
1 parent 183bba2 commit 4dcbbc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Kiwi/KWMock.m
Expand Up @@ -594,7 +594,17 @@ - (id)mutableCopy {
#pragma mark Key-Value Coding Support

- (id)valueForKey:(NSString *)key {
return nil;
KWMessagePattern *messagePattern = [KWMessagePattern messagePatternWithSelector:_cmd];
[self expectMessagePattern:messagePattern];
NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd messageArguments:&key];

if ([self processReceivedInvocation:invocation]) {
id result = nil;
[invocation getReturnValue:&result];
return result;
} else {
return nil;
}
}

- (void)setValue:(id)value forKey:(NSString *)keyPath {
Expand Down
8 changes: 8 additions & 0 deletions Tests/KWMockTest.m
Expand Up @@ -305,6 +305,14 @@ - (void)testItShouldNotRaiseWhenReceivingKVCMessagesAsANullMock {
STAssertNoThrow([mock setValue:@"baz" forKeyPath:@"foo.bar"], @"expected setValue:forKeyPath: not to raise");
}

- (void)testItShouldAllowStubbingValueForKey {
id mock = [Cruiser mock];
id otherMock = [Cruiser mock];
[mock stub:@selector(valueForKey:) andReturn:otherMock withArguments:@"foo"];
id value = [mock valueForKey:@"foo"];
STAssertEquals(value, otherMock, @"expected valueForKey: to be stubbed");
}

@end

#endif // #if KW_TESTS_ENABLED

0 comments on commit 4dcbbc3

Please sign in to comment.