Skip to content

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

@bsautel

Description

@bsautel

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!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions