Skip to content
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

Method parameter injection into fixture methods is broken in 2.0 #1305

Closed
bsautel opened this issue Mar 25, 2021 · 2 comments · Fixed by #1306
Closed

Method parameter injection into fixture methods is broken in 2.0 #1305

bsautel opened this issue Mar 25, 2021 · 2 comments · Fixed by #1306
Assignees

Comments

@bsautel
Copy link

bsautel commented Mar 25, 2021

Issue description

Gradle 7 will be available soon and relies on Groovy 3. As a maintainer of gradle-node-plugin, I tried to see if the project will build using Gradle 7.0-rc1. The plugin tests are based on Spock and there was a Groovy version conflict. It sounds like the only way to get the build work is to upgrade Spock to the 2.0 latest milestone. That's what I did and I encountered this issue.

We created an extension to run the integration tests against multiple Gradle versions. For that, we run each spec multiple times and use parameter injection to get the version available. This extension works as expected using Spock 1.3.

But when I upgrade to Spock 2, it no longer works. I saw that the arguments arrays now has the right size, whereas in the 1.x version it could be smaller and we had to enlarge it.

The problem is that the arguments array is empty whereas my setup method has one parameter that should be injected. For this reason, if I set the first argument to the value I want to inject, I get a java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 error.

If I try to enlarge the arguments array as it was necessary in previous versions, I get a java.lang.IllegalArgumentException: length of arguments array must not change from 0 to 1. MethodInvocation does not let me set one argument since the method has no arguments (which is wrong).

It sounds like the cause of the issue is that the MethodInvocation contains some wrong information.

How to reproduce

I created a GitHub project that shows this issue. Run ./gradlew build to execute it.

Additional Environment information

Java/JDK

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Groovy version

3.0.7

Build tool version

Gradle

6.8.3

Operating System

Ubuntu 20.04

IDE

IntelliJ

Build-tool dependencies used

Gradle/Grails

testImplementation("org.spockframework:spock-core:2.0-M4-groovy-3.0")

Hope this will help to solve this issue. Feel free to ask me further information if needed. Thanks a lot for your work!

@Vampire Vampire self-assigned this Mar 26, 2021
@Vampire Vampire changed the title Method parameter injection is broken in 2.0 Method parameter injection into fixture methods is broken in 2.0 Mar 26, 2021
@Vampire
Copy link
Member

Vampire commented Mar 26, 2021

No further information needed, thank you.
When I improved the whole parameter handling I didn't consider fixture methods and there were no tests for them, only for feature methods.
This should soon be fixed in snapshot build, as soon as my PR got merged.

@bsautel
Copy link
Author

bsautel commented Mar 26, 2021

Nice, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants