luisobo/Nocilla — pull request #53 by brow (2013-11-07 02:18:04+00:00)
Title: Match request body using block

Request bodies are most often encoded as `application/json`, `application/x-www-form-urlencoded`, or `application/xml`. Each of those encodings can represent the same data in more than one way.

For example, in JSON, `{"a":1, "b":2}` is equivalent to `{"b":2, "a":1}`. In fact, some JSON serializers behave nondeterministically as to which of those two emit.

Therefore, it usually doesn't make sense to specify that the body of a request using `-[NSData equals]`. Instead, you usually want to use a notion of equality appropriate to the body encoding.

This pull enables matching a request body using an arbitrary block, like so:

stubRequest(@"POST", @"https://api.example.com/endpoint.json").
withHeaders(@{@"Accept": @"application/json"}).
withBodyWhere(^(NSData *body){
id bodyJSONObject = [NSJSONSerialization JSONObjectWithData:body
options:0
error:NULL];
return [bodyJSONObject isEqual:@{@"a":1, @"b":2}];
});