Problem with @Unroll with groovy-1.8

269 views
Skip to first unread message

Ken Kousen

unread,
Apr 29, 2011, 12:25:51 PM4/29/11
to spockfr...@googlegroups.com
I'm trying to run the basic spock-example that comes with the main distribution, using Groovy 1.8 and 0.5-spock-1.8.

On the spec DataDriven.groovy, I get the following error:

"Only classes and closures can be used for attribute 'value' in @spock.lang.Unroll'

The error is flagging the line
@Unroll("minimum of #a and #b is #c")

This worked fine with Groovy 1.7. Has something fundamental changed here? How do I fix it?

Thanks,

Ken Kousen

Peter Niederwieser

unread,
Apr 29, 2011, 2:51:11 PM4/29/11
to spockfr...@googlegroups.com
spock-core-0.5-groovy-1.8 was an experimental release based on Groovy 1.8 beta 2 (or 3?) and is outdated. If you want to use Spock with Groovy 1.8 at this time, please use spock-core-0.6-groovy-1.8-SNAPSHOT.
Not exactly sure why you get the error, but it's related to a change in spock-core-0.5-groovy-1.8 (use of Groovy 1.8's annotation closures for @Unroll) that has meanwhile been undone. So switching to 0.6-SNAPSHOT should solve your problem.

Cheers,
Peter

Ken Kousen

unread,
Apr 30, 2011, 7:28:35 AM4/30/11
to spockfr...@googlegroups.com
I went to the build.gradle file for the spock-example and edited to:

groovy("org.codehaus.groovy:groovy-all:1.8.0")
testCompile "org.spockframework:spock-core:0.6-groovy-1.8-SNAPSHOT"

I got a bunch of new downloads, as expected, but the same error on the same class. It still doesn't understand a string argument for @Unroll.

Peter Niederwieser

unread,
Apr 30, 2011, 5:01:44 PM4/30/11
to Spock Framework - User
Not sure what exactly you are doing (e.g. which version of the spock-
example project you are using), but if you clone Spock from GitHub and
check out the 'groovy-1.8' branch, all tests in spock-example should
pass (I made some fixes today). Note that the spock-example project
has its own Gradle build, and isn't currently built as part of the
overall Gradle build.

Cheers,
Peter

Kenneth Kousen

unread,
Apr 30, 2011, 9:06:00 PM4/30/11
to spockfr...@googlegroups.com
Ah, I get it now. I cloned the repo, but I didn't switch branches to groovy-1.8 before running the build. Now I have it right.

I also see that the way you fixed the problem was to wrap the string inside a closure, i.e.,

@Unroll({"minimum of $a and $b is $c"})

Thanks for your help,

Ken


--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.




--
Kenneth A. Kousen
President
Kousen IT, Inc.

Peter Niederwieser

unread,
Apr 30, 2011, 9:28:10 PM4/30/11
to spockfr...@googlegroups.com
At the risk of confusing you further, until this moment I thought that I had undone this change shortly after the release of 0.5-groovy-1.8, but apparently I haven't. Can't say right now if this change (usage of annotation closures for @Unroll) will make it into 0.6-groovy-1.8, which I consider the first official release supporting 1.8.

Cheers,
Peter

Robert Fletcher

unread,
Jun 3, 2011, 4:29:00 AM6/3/11
to spockfr...@googlegroups.com
I just got bitten by this today when trying to upgrade to the
groovy-1.8 version of Spock for Grails 1.4. This is a pretty
significant breaking change. I have hundreds if not thousands of
@Unroll calls scattered across numerous projects. I'm not sure I
understand what using a Closure parameter offer that's useful to
@Unroll to justify the change.

Rob

Peter Niederwieser

unread,
Jun 4, 2011, 3:01:00 AM6/4/11
to Spock Framework - User
On Jun 3, 4:29 am, Robert Fletcher <robert.w.fletc...@gmail.com>
wrote:
> I'm not sure I understand what using a Closure parameter offer that's useful to
> @Unroll to justify the change.

We had our reasons, but we also listen to our users (especially the
long-eared DJ's among them). Hereby I'm happy to announce that we've
decided to revert the change before the 0.6 release. So all your prior
investments in @Unroll are safe. You'll still be tempted to touch them
though, because the new recommended syntax is almost irresistible:

@Unroll
def "you'll want to #touch.touch.touch me #here"() { ... }

Cheers,
Peter

Robert Fletcher

unread,
Jun 9, 2011, 12:37:09 PM6/9/11
to spockfr...@googlegroups.com
I've been playing with the new syntax and to some extent I can see the
advantages, particularly in that you can do more complex things with
params in a GString than were possible with the # expression.

However, the new proposal is fantastic news. That's what I've been
hoping @Unroll would be able to do all along!

Matias Bjarland

unread,
Dec 2, 2011, 5:48:55 AM12/2/11
to spockfr...@googlegroups.com
Hi Peter, from one forum to another. The new syntax looks beautiful! The duplication in unrolled spock method declarations has been bugging me for a while. I.e it would be really nice to rewrite: 

  @Unroll("Expect value '#expectedValue' from manifest List property '#propertyName'")
  def "Expect value 'expectedValue' from manifest List property 'propertyName'"() { 
    ...some test code...
  }

as

  @Unroll
  def "Expect value '#expectedValue' from manifest List property '#propertyName'"() { 
    ...some test code...
  }

and it looks like this is exactly what your new unroll syntax does. This would be beautiful. 

Does the new syntax exist in a snapshot version? As per our discussion on the gradle forums I just upgraded to M6 and the latest "spock-core-0.6-groovy-1.8-20111202.050205-347" snapshot still seems to expect the "@Unroll( { ... } )" closure syntax. 

mbjarland

unread,
Dec 3, 2011, 6:11:30 PM12/3/11
to spockfr...@googlegroups.com
Ok, thanks. And no problem, I am happy to wait for the syntax. Just wanted to
make sure I wasn't missing something that was already out there. And
apologies for the cross post.

And thank you for a great BDD framework! And for fixing our gradle issues!

--
View this message in context: http://spock-framework.3207229.n2.nabble.com/Problem-with-Unroll-with-groovy-1-8-tp6317496p7058938.html
Sent from the Spock Framework mailing list archive at Nabble.com.

Peter Niederwieser

unread,
Dec 3, 2011, 5:54:02 PM12/3/11
to spockfr...@googlegroups.com

mbjarland wrote
>
> Hi Peter, from one forum to another. The new syntax looks beautiful! [...]

> Does the new syntax exist in a snapshot version?
>

No, the proposed new syntax hasn't been implemented yet.

Cheers,
Peter


--
View this message in context: http://spock-framework.3207229.n2.nabble.com/Problem-with-Unroll-with-groovy-1-8-tp6317496p7058904.html

Reply all
Reply to author
Forward
0 new messages