Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nakp opened this issue Oct 13, 2016 · 1 comment
Closed

Comments

@nakp
Copy link

nakp commented Oct 13, 2016

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 nakp changed the title Use predicate when filtering mock objects Use predicate in stubbed properties when filtering mock objects in array Oct 14, 2016
@nakp
Copy link
Author

nakp commented Oct 20, 2016

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

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

@nakp nakp closed this as completed Oct 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant