kiwi-bdd / Kiwi

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

Use predicate in stubbed properties when filtering mock objects in array #687

Closed nakp closed 7 years ago

nakp commented 7 years ago

I have 2 mock's in a array, and properly stubbed both's name property (mock1.name = @"mock1" and mock2.name = @"mock2", items is the array holding both objects)

[mock1 stub:@selector(name) andReturn:@"mock1"];

...

NSPredicate *filter= [NSPredicate predicateWithFormat:@"name = %@", @"mock1"];
NSArray *filteredArray = [items filteredArrayUsingPredicate:filter];

returns an empty array, can't we use stubs with predicates?

nakp commented 7 years ago

The solution is to also stub the method valueForKey that NSPredicate uses, like this:

[mock1 stub:@selector(valueForKey:) andReturn:@"mock1" withArguments:@"name"]