pact-specification
pact-specification copied to clipboard
Matching Arrays without structure
Is it possible to match an array where each array element it _not_ a json object?
i.e.
def expectedArray = ['12:00', '12:15', '12:30']
and then in my matcher
withBody {
foo minLike(1) {
regex('\\d{2}:\\d{2}', '12:00')
}
}
Based on the doco, it seems each array matchers requires the element of the array to be a json object with some structure.
The following matcher definitions should match your array:
"matchingRules": {
"$.body.foo": {"min": 1, "match": "type"},
"$.body.foo[*]": {"match": "regex", "regex": "\\d{2}:\\d{2}"}
}
I'll add a test case to represent this example.
Thanks, Looks reasonable, what would be the correct usage of the dsl to generate this spec?
You'll prob have to raise an issue with the DSL project to generate the correct matchers, but I could imagine something like:
withBody {
foo minLike(1) [
regex('\\d{2}:\\d{2}', '12:00')
]
}