Use predicate in stubbed properties when filtering mock objects in array
nakp opened this issue · 1 comments
nakp commented
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
The solution is to also stub the method valueForKey that NSPredicate uses, like this:
[mock1 stub:@selector(valueForKey:) andReturn:@"mock1" withArguments:@"name"]