Open QMG-kazala opened 6 years ago
Anyone? Anything? Is there a chance notNull() matcher (or map() or anything similar) will be added in the future?
This is impossible to support with the current implementation. The behaviour is to apply the matchers at the attribute level, and you can't apply them conditionally based on a predicate.
What we need to be able to apply a set of matchers based on a predicate:
validatedAnswers minLike(1) {
when(type == "typeA") {
favourite_colour string()
...
}
}
But this will not be possible to implement without a change to the specification.
Oh yes!!!! Having predicate-based matchers would solve so many problems! It would be great :D 👍 Does it mean it's planned for version 4?
Yes it will have to be a V4 change because it will require a change to the pact file format as well as how the matchers are applied.
@uglyog will this be included in V4?
@alexfdz we are going to look at having sets of matching rules applied to different objects in lists. https://github.com/pact-foundation/pact-specification/issues/38 will track this.
My problem is I have a field which is a list (an array) of maps. Each map can have elements of different types (strings or sub-maps), eg.
and we're only interested in some of those answers.
What we really need is this: https://github.com/pact-foundation/pact-specification/issues/38, but it's planned for v.4. In the meantime we're trying a different approach. What I'm attempting to do now is to specify that each element of the list is a non-empty map. Another approach is to specify that each element of the list is not null. Can any of this be done using Groovy DSL?
This:
doesn't work because it mean
answers
is expected to be empty ("Expected an empty Map but received Map( [...] )", see also https://github.com/DiUS/pact-jvm/issues/298).So what I would like to do is something like this:
or:
or:
Can it be done?