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
Mock Groovy Object expecteding "get" rather than "is" with dot notation accessor #1256
Comments
Good catch! I can confirm this, provided that the class under test (CUT) is a (stand-alone) Groovy class. The problem does not occur if the CUT is a Java class or a static inner class of the specification. I can also confirm that in Spock 1.3 there is no issue while in 2.0-M4 there is one. |
fixes #1256 Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
@kriegaex - FWIW, it appears I am running into the same issue with |
Probably it will never be fixed in 1.3, but I would like to see a reproducer anyway because when I tested it, there was no problem. Maybe there is a corner case which should also be checked in 2.0. |
Here it is:
|
I am glad I asked for the MCVE. This is a similar issue, but not exactly the same as the one fixed here. Otherwise your specification would work in Spock 2 master and fail in 1.3. It fails in both versions, though, so this is kind of an extension of the existing issue, seemingly affecting Groovy mocks/spies. @leonard84, @Vampire, any opinions how you would like to handle this? Reopen or new issue? |
A new issue would be better, as the OP one was for java mocks. |
Opened new issue. (#1270) |
@leonard84, maybe you want to rename both issues in order to make them more easily distinguishable from each another. I do not have the necessary rights. That would also be helpful for the issue list in the next release. At the same time you could fix the little "expecteding" typo. |
Issue description
In our testing of a groovy / grails application we have an object under test, into which we inject a Mock of an object, to mock out a method that is called. In our migration to spock 2 (org.spockframework:spock-core:2.0-M4-groovy-3.0) we have hit an issue when the mock object has a method that returns a boolean - the method cannot be found when accessed by groovy's dot notation accessor.
When the dot notation is used for a boolean it looks for a method with "get" as the method prefix rather than "is". I have recreated this in a standalone groovy script (which I will link to). So the Mock is an mock of a real object, which the class is:
When this ExampleData is created as a Mock, its then called in the controller as follows:
When this is called - we get the following error:
So you can see when accessed via dot notation then you can see that its looking for
getCurrent()
rather thanisCurrent()
How to reproduce
So this can be reproduced with the following groovy code:
To run:
You will see the error as per the description.
I can show that this works with previous version of spock by changing the dependency:
and running with groovy v2. This works
Additional Environment information
Java/JDK
Groovy version
Build tool version
Grapes
Operating System
Mac OS X 10.15.5
Build-tool dependencies used
Groovy Grape
The text was updated successfully, but these errors were encountered: