Closed orgi closed 4 years ago
I can confirm the problem in Spock 1.3. What is interesting is that if I add some diagnostic output
1 * fooBar.foo { args ->
args.test.any {
println it
it == 'bar'
}
}
it unexpectedly prints 5 lines, not just 2:
foo
foo
foo
foo
foo
I also tried in Spock 2.0-M4-groovy-3.0 where it works as expected. The test passes and prints:
foo
bar
After a cursory look my guess is that this was fixed by #1205, so my suggestion would be to update to Spock 2.0-M4
Issue description
I converted some of our test code from using
Mock
toGroovyMock
since we are mainly testing dynamic methods.It seems like it is not possible to use any kind of looping construct as part of the argument constraints, e.g.
How to reproduce
Use the following piece of groovy code as part of some spec:
Putting a breakpoint inside the
any {}
closure reveals that every time I reach this breakpoint the value ofit
is 'foo'. However I would have expected that for the second time it becomes ' bar' to make the test pass...Some time back this used to work for us. Now when creating this small example I could not get it working, neither using
Spy
orGroovySpy
norMock
orGroovyMock
.Hope I did not do any obvious mistake while creating the example.
Additional Environment information
Java/JDK
java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
openjdk version "1.8.0_212-1-ojdkbuild" OpenJDK Runtime Environment (build 1.8.0_212-1-ojdkbuild-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
Groovy version
2.4 / 2.5 Tried both versions
Build tool version
Gradle
Using gradle 6.4
Operating System
Windows 10 2004
IDE
IntelliJ
Build-tool dependencies used