Skip to content

Conversation

@ryansch
Copy link

@ryansch ryansch commented Nov 14, 2013

In my integration request specs, I sometimes want to find out if a json response contains objects with specific ids. With the existing interface I have to go through and explicitly blacklist all of the other keys. I instead added a whitelist with the #only method.

Example:

# include_json
%([{"id":1,"json":"spec"}]).should include_json(%({"id":1})).only(:id)

# be_json_eql
%({"id":1,"json":"spec"}).should be_json_eql(%({"id":1})).only(:id)

The actual json responses I'm comparing have far more keys.

@charlierudolph
Copy link

This can actually be done with the current interface

First example:

%([{"id":1,"json":"spec"}]).should be_json_eql(1).at_path("0/id")

Second example:

%({"id":1,"json":"spec"}).should be_json_eql(1).at_path("id")

@ryansch
Copy link
Author

ryansch commented Nov 27, 2013

picard-facepalm

@ryansch ryansch closed this Nov 27, 2013
@ryansch ryansch deleted the only-keys branch November 27, 2013 00:27
@ryansch ryansch restored the only-keys branch December 11, 2013 06:08
@ryansch ryansch deleted the only-keys branch February 17, 2015 00:55
@ryansch ryansch restored the only-keys branch February 17, 2015 00:56
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.

2 participants