kiwi-bdd / Kiwi

Simple BDD for iOS
BSD 3-Clause "New" or "Revised" License
4.14k stars 512 forks source link

KWMock should comply to key-value coding #560

Open jonasfa opened 10 years ago

jonasfa commented 10 years ago

Should work, but doesn't:

MyClass *mock = [MyClass mock];
[mock stub:@selector(property) andReturn:@"something"];
NSLog(@"%@", [mock valueForKey:@"property"]); // => (null)

Stubbing valueForKey: would be painful for a complex KeyPath. Eg, with a collection: [arrayOfMocks valueForKeyPath:@"@unionOfObjects.something"]

There is official documentation on the default implementation of valueForKey:: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/SearchImplementation.html#//apple_ref/doc/uid/20000955-138234-BAJCAJGJ

jonasfa commented 10 years ago

No comments? I could work on it if you agreed with such change... I just don't want to work on something that may be rejected later.

TristanBurnside commented 9 years ago

I would also like to see this added

dispatchMain commented 6 years ago

Definitely required. Not sure why nobody has looked at this issue for so long? Even partial mocks return nil for valueForKey though actual object returned correct value. In KWMock, we need to stub valueForKey and valueForKeyPath explicitly if mock is expected to respond to those. But that should be default behaviour as in normal objects.