IncludeJson matcher doesn't properly match arrays at a path. #32

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@michalorman

I've committed a fix for IncludeJson matcher so that arrays at a path are properly matched.

@laserlemon

This comment has been minimized.

Show comment Hide comment
@laserlemon

laserlemon Oct 3, 2012

Contributor

This is somewhat related to #31. I think this comes from a misunderstanding of the intent of the "include" matcher. The matcher only passes if the JSON (array or hash) includes the given element. So if you give an array argument, the JSON must include that array as an element.

To illustrate:

[1, 2, 3] does not include [1, 2].
[1, 2, 3] does include 2.
[[1, 2], 3] does include [1, 2].

In terms of evaluating inclusion at a path, the rules are the same:

{"one": [2, 3], "four": [5, 6]} does not include [2, 3] at path "one".
{"one": [2, 3], "four": [5, 6]} does include 2 at path "one".
{"one": [2, 3], "four": [5, 6]} does include [2, 3].

What I think you may be looking for is:

%({"one": [2, 3], "four": [5, 6]}).should be_json_eql(%([2, 3])).at_path("one")

What you're describing is equality, not inclusion. I hope that helps clear it up! Thank you for the pull request.

Contributor

laserlemon commented Oct 3, 2012

This is somewhat related to #31. I think this comes from a misunderstanding of the intent of the "include" matcher. The matcher only passes if the JSON (array or hash) includes the given element. So if you give an array argument, the JSON must include that array as an element.

To illustrate:

[1, 2, 3] does not include [1, 2].
[1, 2, 3] does include 2.
[[1, 2], 3] does include [1, 2].

In terms of evaluating inclusion at a path, the rules are the same:

{"one": [2, 3], "four": [5, 6]} does not include [2, 3] at path "one".
{"one": [2, 3], "four": [5, 6]} does include 2 at path "one".
{"one": [2, 3], "four": [5, 6]} does include [2, 3].

What I think you may be looking for is:

%({"one": [2, 3], "four": [5, 6]}).should be_json_eql(%([2, 3])).at_path("one")

What you're describing is equality, not inclusion. I hope that helps clear it up! Thank you for the pull request.

@laserlemon laserlemon closed this Oct 3, 2012

@michalorman

This comment has been minimized.

Show comment Hide comment
@michalorman

michalorman Oct 3, 2012

Great, that was exactly what I was looking for. Thanks!

Great, that was exactly what I was looking for. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment