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

Add JSON support #77

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add JSON support #77

wants to merge 6 commits into from

Conversation

robb
Copy link
Contributor

@robb robb commented Sep 15, 2014

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.

@@ -3,7 +3,7 @@
#import "LSHTTPStubURLProtocol.h"

SPEC_BEGIN(LSNSURLHookSpec)
describe(@"#load", ^{
pending(@"#load", ^{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️

@robb
Copy link
Contributor Author

robb commented Sep 15, 2014

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

id json = [NSJSONSerialization JSONObjectWithData:selfBody options:0 error:NULL];
id other = [NSJSONSerialization JSONObjectWithData:reqBody options:0 error:NULL];

if (json != nil && [json isEqual:other]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json != nil is unnecessary

@robb
Copy link
Contributor Author

robb commented Sep 17, 2014

Build failed because xctool is already installed 😒

@luisobo
Copy link
Owner

luisobo commented Jun 24, 2015

@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.

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

Successfully merging this pull request may close these issues.

None yet

2 participants