I'm using the Spock framework for testing, and I have a question regarding multivaraible assignment in a where clause.
I have the following test case:
def "sending a message delegates to message sender"() {
when:
sendMessage(x,y)
then:
1 * messageSender.send(x,y)
where:
x << 1
y << 2
}
I want to replace the multiple variable assignments in the where clause with a single assignment operation. I tried:
where:
[x,y] << [1,2]
but got a MissingMethod exception. I assume this is because the expression [1,2] is treated as an array rather than a list.
Note that the following worked:
where:
[x,y] << [1,2].combinations()
It seems that the combinations() method returns a List type, but despite that the following did not work:
where:
[x,y] << [1,2].asList()
Using combinations() is counter-intuitive, so I am wondering if there is a simple, elegant way of initializing multiple variables in Spock.
edit: I am using spock version 0.7-groovy-2.0