Unexpected behaviour when Spock datatable's header contains variable named like variable in the other feature method

Viewed 572

I have a problem with data-driven tests in Spock. When datatable header contains variable (in this case 'b') named like variable in the other feature method, the following exception is thrown:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '3' with class 'java.lang.Integer' to class 'java.util.UUID'

Example specification class:


class ExampleSpec extends Specification {

    def 'example feature with variable named like datatable header'() {
        given:
        UUID b = UUID.randomUUID()

        when:
        def length = b.toString().length()

        then:
        length == 36
    }

    def "maximum of two numbers"() {
        expect:
        Math.max(a, b) == c

        where:
        a | b | c
        1 | 3 | 3
        0 | 0 | 0
    }
}

Does anyone know what the reason is that datatable's header variable interferes in such an unexpected way with a variable defined in the previous feature method?

The problem occurs only in version: '1.x-groovy-2.5'.

0 Answers
Related