pact-foundation / pact-specification

Describes the pact format and verification specifications
MIT License
297 stars 28 forks source link

Matching Arrays without structure #25

Open georgepapas opened 8 years ago

georgepapas commented 8 years ago

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.

uglyog commented 8 years ago

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.

georgepapas commented 8 years ago

Thanks, Looks reasonable, what would be the correct usage of the dsl to generate this spec?

uglyog commented 8 years ago

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')
   ]
}