imbo / behat-api-extension

API extension for Behat, used to ease testing of JSON-based APIs
MIT License
107 stars 42 forks source link

Add extra test for custom matcher #87

Closed christeredvartsen closed 4 years ago

christeredvartsen commented 4 years ago

Add example from https://github.com/imbo/behat-api-extension/issues/86 to verify custom matcher behavior.

christeredvartsen commented 4 years ago

I added a scenario now that requests an endpoint that responds with:

[
  {
    "integer": 123,
    "string": "value"
  }
]

and to target the string value I used the following:

Then the response body contains JSON:
"""
{
    "[0]": {
        "string": "@myMatcher()"
    }
}
"""

when I targeted the integer value to force an error the following error message is generated:

Want string yo

================================================================================
= Needle =======================================================================
================================================================================
"@myMatcher()"

================================================================================
= Haystack =====================================================================
================================================================================
123

The way to target numerically indexed arrays might be somewhat weird, but it should be thoroughly documented here: https://behat-api-extension.readthedocs.io/en/latest/guide/verify-server-response.html#match-specific-keys-in-a-numerically-indexed-array-key-index

dFayet commented 4 years ago

Yes you got it :-) Thank you for your time.

christeredvartsen commented 4 years ago

No worries.