When the variable in the where clause is named with the same name in the other test but the types are different, the data driven test is trying to cast it to the wrong type.
org.codehaus.groovy:groovy-all:2.5.6
org.spockframework:spock-core:1.3-groovy-2.5
cglib:cglib-nodep:3.2.12
The error that I am getting is
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'str' with class 'java.lang.String' to class 'com.togise.hello.Hello'
If I rename the variable in the where clause to something else the test passes.
The code can be found at AppTest.groovy
Here is code as well
package com.togise
import com.togise.hello.Hello
import spock.lang.Specification
class AppTest extends Specification {
def "application has a greeting"() {
setup:
def app = new App()
Hello hello = new Hello(str: "str")
when:
def result = app.greeting
then:
result != null
hello != null
}
def "when the variable in the where clause is named with the same name with in some other test in this class but the types are different, the test is trying to cast it to the wrong type"() {
App app = Mock()
when:
new String()
then:
app.getGreeting() >> hello
where:
hello << ["str"] // matches the name of the variable in the previous test
}
}
It seems this is a known bug https://github.com/spockframework/spock/issues/880 and it is still open.
The workaround is to rename the variable in the where clause for now.
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