Mock using implicit valueForKeyPath?

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Mock using implicit valueForKeyPath?

Postby itsthejb » 19 Sep 2012, 15:27

Hi everyone,

First post, so just like to say I've been using OCMock for some years now and really appreciate the great work done here. Keep it up!

Query/feature suggestion coming up;

I've had a lot of pain over the years setting up testing states on objects that have a lot of sub-properties; creating mocks for each, stubbing the right properties, stubbing sub-mock objects, etc. etc. Let me illustrate in pseduo-code;

Code: Select all
@class A
@property () FooProperty *foo
@end

FooProperty *testFoo = [OCMockObject mockForClass:[FooProperty class]];
A *testObject = [[A alloc] init];
A.foo = testFoo;


Now imagine that FooProperty has a big hierarchy and class A can do things like;

Code: Select all
id name = self.foo.address.line1.name;


It would be wonderful if I could set up this state with something like;

Code: Select all
[[[testFoo stub] andReturn:@"Bar"] forKeyPath:@"address.line1.name"]


This doesn't seem to work at the moment because A doesn't explicitly use valueForKeyPath, such as;

Code: Select all
id name = [self.foo valueForKeyPath:@"address.line1.name"]


Can this already be done? If not, it doesn't seem like it would be too challenging to add - something like using -valueForUndefinedKeyPath?

I hope my description is understandable! Thanks for your help!
itsthejb
 
Posts: 1
Joined: 19 Sep 2012, 15:13

Return to OCMock



cron