New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

mkosmul opened this Issue Sep 26, 2016 · 0 comments


None yet
1 participant

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 1.8.0_73-b02

Groovy version

groovy 2.4.7

Build tool version


gradle 3.1

Operating System



IntelliJ 2016.2 Ultimate

Build-tool dependencies used


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