Join GitHub today
Not able to use global GroovyMock in setupSpec() #791
When trying to setup some class globally using GroovyMock(i.e. GroovyMock(StringUtils, global: true)) in setupSpec, Spock throws exception saying:
After digging a little bit more, I found out that this is thrown here:
And by reading the code, it seems to be caused by the fact that Spock is trying to attach a cleanup process to iteration which is failed because setupSpec is outside any test iteration.
I'm not entirely sure if this is as designed or a bug. I couldn't find anything on the documentation saying you are not supposed to use GroovyMock in setupSpec. Documentation is only specifying that you are not supposed to reference instance fields unless they are annotated with @shared which is clearly not the case here.
So I'm reporting it here and hoping it can be either fixed or at least the documentation be made clearer that this is a limitation one should not be doing.
How to reproduce
For example a simple test case like this:
Will fail with the following message:
Additional Environment information
java version "1.8.0_151"
It is not a bug, but maybe it should be mentioned somewhere. Mocks are always bound to a
@leonard84 thanks for the explanation. That's what I thought as well. And I strongly agree with this should be mentioned somewhere in the documentation. Also the exception here should be clearer in reflecting what the real problem is. Right now saying