Когда переменная в предложении where названа с тем же именем в другом тесте, но типы различаются, тест на основе данных пытается привести ее к неправильному типу.
org.codehaus.groovy:groovy-all:2.5.6
org.spockframework:spock-core:1.3-groovy-2.5
cglib:cglib-nodep:3.2.12
я получаю ошибку
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Невозможно привести объект 'str' с классом 'java.lang.String' к классу 'com.togise.hello.Hello '
Если я переименую переменную в предложении where во что-то еще, тест пройден.
Код можно найти по адресу AppTest.groovy
Здесь также есть код
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
}
}