It's an idiom I also use from time to time. At one point I thought about supporting something like this:
where:
key | expectation
"base case"
"no-args" | true
"key not present"
"xyzzyz" | false
"case insensitive"
"No-Args" | true
But I wasn't fully convinced. If the body of the test is short (like here), I nowadays tend to go for the straightforward:
def "base case"() {
expect:
messages.contains("no-args")
}
def "key not present"() {
expect:
...
}
I'm still considering to support somethink like this, which can be handy at times (and is a frequent idiom in JUnit):
@Fragment // not a standalone/complete feature method but can use full syntax
def containsKey(key, expectation) {
expect:
messages.contains(key) == expectation
}
def "base case"() {
containsKey("no-args", true)
}
def "key not present"() { ... }
If all you need is assertions, you can of course just go:
void containsKey(key, expectation) {
assert messages.contains(key) == expectation
}
def "base case"() {
expect:
containsKey("no-args", true)
}
Is there anything here that you like?
Cheers,
Peter