luisobo / Nocilla

Testing HTTP requests has never been easier. Nocilla: Stunning HTTP stubbing for iOS and Mac OS X.
https://twitter.com/luisobo
MIT License
1.84k stars 172 forks source link

Add JSON support #77

Open robb opened 10 years ago

robb commented 10 years ago

As alluded to on Twitter, this allows users to use JSON in request and response bodies. E.g.:

stubRequest(@"POST", @"http://server.dev/user")
    .withJSON(@{ @"name": @"robb", @"pw": @"foobarbaz" })
    .andReturn(201);

BOOL success = [client signUpWithUserName:@"robb" password:@"foobarbaz"];

It works by parsing the JSON contents if the header are set appropriately and comparing the dictionaries, which makes us independent of internals of NSJSONSerialization.

I had some trouble getting master to build on my machine and in Xcode 6. I updated some of the dependencies to please the compiler but had to mark two tests as pending for the time being.

robb commented 10 years ago

Would be great if someone more familiar with Kiwi, Mocking or Nocilla could chime in on the :warning:

robb commented 10 years ago

Build failed because xctool is already installed :unamused:

luisobo commented 9 years ago

@robb I just outlined here the ideal way of implementing support for arbitraty matching logic. This approach has been possible from day one, it didn't occur to me to use it for json, apologies.

I like better the approach outlined there because it keep the surface of the DSL to a minimum, and does not couple the DSL to specific content types, which has been always my concern about implementing JSON support this particular way.

Let me know what you think.