"Where-blocks may only contain parameterizations" error in Spock

Error in Spock

Run the test in Spock.

import spock.lang.*

class DataDrivenSpec extends Specification {

    def "a + b == sum"() {
        expect:
        a + b == sum

        where:
        a | b || sum
        1 | 2 || 3
        3 | 1 || 4
    }
}

By the way, the setting of build.gradle is as follows.

build.gradle

build.gradle


plugins {
    id 'groovy'
}

group 'old-spock-sample'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.5'
    // https://mvnrepository.com/artifact/org.spockframework/spock-core
    testCompile group: 'org.spockframework', name: 'spock-core', version: '0.5-groovy-1.7'
}

Then I got the following error:

where-blocks may only contain parameterizations (e.g. 'salary << [1000, 5000, 9000]; salaryk = salary / 1000')

There seem to be multiple reasons for this error. I think it's a rare pattern, but in my case it was because the version of Spock was old.

Reason

Spock's Release Notes states:

0.6 (released 2012-05-02)

(Omitted)

Improved Data Table Syntax

Table cells can now be separated with double pipes. This can be used to visually set apart expected outputs from provided inputs:

...
where:
a | b || sum
1 | 2 || 3
3 | 1 || 4

In Spock, the expected value of the parameterization test||What is written after is Spock's 0.Since it is a function added in 6, it seems that it can not be used depending on the version. (Currently (May 2020) the latest version is 1.3) The solution is simply||To|You can execute it by setting. Alternatively, increasing the version of Spock should solve the problem. Since it is a function that is used as a matter of course, I did not have the idea that it may not be available depending on the version, and I personally struggled because I could not immediately understand the cause from the error message. Be careful when using a very old version of Spock.

Recommended Posts

"Where-blocks may only contain parameterizations" error in Spock
ERROR: In file ./.env: environment variable name'THOR_SILENCE_DEPRECATION' may not contain whitespace.