Rinke van den Berg
12/29/2022, 12:53 AMmax=1
but not max=0
.Timothy Jones
12/29/2022, 1:38 AM3. A scenario where the array contains max=0 is not verifiable (I can specify an empty array, but PACT would still allow a non-empty array).No, it wonât. If youâre experiencing this, itâs a bug.
Timothy Jones
12/29/2022, 1:39 AMeachLike
matcher in the empty array case. When the array is empty, you donât need a matcher, you just specify an empty array.Timothy Jones
12/29/2022, 1:40 AMTimothy Jones
12/29/2022, 1:43 AMeachLike
for this)
⢠Array that includes these specific items in any order
etcTimothy Jones
12/29/2022, 1:43 AMTimothy Jones
12/29/2022, 1:45 AMTimothy Jones
12/29/2022, 1:47 AMIâm also working on something that will be pact-compatible, we could compare notesOne of the things Iâd like to do is to review the pact-jvm source code (where the pact matchers are all described clearly) and write up how each one behaves. I want to do this so that I can read pact files correctly - itâs not at the top of my todo list yet, but if this is the kind of thing your tool will also need, it definitely would be worth comparing notes.
Timothy Jones
12/29/2022, 1:53 AMIt therefore seems arbitrary to allow max=1 but not max=0.I believe the reason for this choice is that itâs normally something people want to be able to specify when thereâs a misuse or misunderstanding - so preventing it brings them to the help pages or FAQ instead of writing a broken test by mistake. The framework could treat
max=0
as []
, but think about how it would work if Pact didnât exist, and instead a coworker was describing the response to you:
âOk, I need exactly zero items, each of which matches this templateâ
âŚ.youâd be like âwait, what? What do you mean?â.
It would be better to have your coworker say:
âOk, I need an empty arrayâ
âGot itâ
And thatâs why instead of eachLike(item, {max: 0})
, you should say []
Timothy Jones
12/29/2022, 1:54 AMTimothy Jones
12/29/2022, 1:54 AMRinke van den Berg
12/29/2022, 5:23 AM{
id: 1,
text: 'hello world',
items: [],
}
So id would be a number, text would be a string and items would be an array.
Now if I want items to be zero-length in some scenario, I cannot have the { match:'type' }
on root, because it will then force items to be an any-length array.
So in this scenario, I would have to be specific about matching id
to be a number
and text
to be a string
because I can't use { max:0 }
as a matcher on $.todos
Is this correct?Rinke van den Berg
12/29/2022, 5:32 AMRinke van den Berg
12/29/2022, 5:42 AMTimothy Jones
12/29/2022, 6:52 AMIs this correct?No. You can cancel the match and go back to exact for
items
(I forget what itâs called in the pact file format, but thereâs a âmatch this exactlyâ), or you could do match of "type"
on both the id
and the text
instead of on the root.Timothy Jones
12/29/2022, 9:21 AMAt some point I thought the pact_verifier_cli would be the reference implementation to look at?My understanding is that theyâre the same behaviour. When I was asking Ron if the matchers were documented anywhere, he said they werenât documented in the spec, but pointed me at this: https://github.com/pact-foundation/pact-jvm/blob/master/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/MatcherExecutor.kt#L142
Timothy Jones
12/29/2022, 9:22 AMRinke van den Berg
12/31/2022, 8:47 AMTimothy Jones
01/01/2023, 12:37 PMMatt (pactflow.io / pact-js / pact-go)