I just noticed that Spock does not assert the conditions if I add an if
clause in the expect block as in
def myTest() {
given:
a = true
expect:
if ( a ) {
1 == 2
}
else {
1 == 1
}
}
The above test will pass since the conditions are not checked. Or the condition checking does not get forwarded pass the if statement.
The workaround to this is to add assert
statements inside the if block, i.e. assert 1 == 2.
What I'm interested is, is why the functionality is like this? Is there some other way to workaround this? I'm assuming this has something to do with Groovy if statement functionality, but I don't know the language details well enough. Most probably the if statement does not return anything for the Spock's expect block to work with.
This has nothing to do with groovy. Spock's documentation clearly states that only top-level expressions are considered in then
and expect
as conditions. It is by design.
Search the link for top.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With