Provide a meaningful error message when trying to stub final method in Kotlin class #650

Open
mkosmul opened this Issue Sep 26, 2016 · 0 comments

Projects

None yet

1 participant

@mkosmul
mkosmul commented Sep 26, 2016

Issue description

In Kotlin, methods are final by default - an explicit open keyword is needed in order to make a method non-final. The same applies to classes. When a Spock test stubs a class and tries to stub a call to such a final method, the stubbing has no effect (the default return value is returned as if no stubbing of this method call) but also no error is visible in the logs which makes this issue very hard to track.

How to reproduce

  • Declare a Kotlin class with a single method m() which is not open
  • In a Spock test create a Stub(YourClass) and stub the call to m() with any value
  • The call still returns the default value (usually null) despite stubbing; no warning is shown in the logs or elsewhere

Additional Environment information

spock 1.0-groovy-2.4

Java/JDK

java 1.8.0_73-b02

Groovy version

groovy 2.4.7

Build tool version

Gradle

gradle 3.1

Operating System

Linux

IDE

IntelliJ 2016.2 Ultimate

Build-tool dependencies used

Gradle/Grails

testCompile {
"org.spockframework:spock-core:spock 1.0-groovy-2.4",
"org.spockframework:spock-spring:spock 1.0-groovy-2.4",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment