Closures within setup or features

12 views
Skip to first unread message

groovybayo

unread,
Dec 7, 2011, 12:20:47 PM12/7/11
to Spock Framework - User
Excuse my ignorance, but is there any reason closures can't be used
within setup blocks or within a feature in general.

Given a simple specification like so,

class HelloWorldSpec extends Specification {

def "can a closure be used"(){
setup:
3.times { println ${it} }
}
}

I get:

groovy.lang.MissingMethodException: No signature of method:
spocktests.HelloWorldSpec.$() is applicable for argument types:
(spocktests.HelloWorldSpec$_spock_feature_0_0_closure1_closure2)
values: [spocktests.HelloWorldSpec
$_spock_feature_0_0_closure1_closure2@5bd6fbb3]
Possible solutions: is(java.lang.Object), any(),
old(java.lang.Object), any(groovy.lang.Closure),
use([Ljava.lang.Object;), wait()
at spocktests.HelloWorldSpec.can a closure be
used_closure1(HelloWorldSpec.groovy:8)
at groovy.lang.Closure.call(Closure.java:410)
at groovy.lang.Closure.call(Closure.java:423)
at spocktests.HelloWorldSpec.can a closure be
used(HelloWorldSpec.groovy:8)

Erick Dovale

unread,
Dec 7, 2011, 12:27:49 PM12/7/11
to spockfr...@googlegroups.com
are you not missing the quotes?
3.times{println "${it}"}
or alternatively you can drop the $ and go with 3.times{println it}




--
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.


groovybayo

unread,
Dec 7, 2011, 12:29:18 PM12/7/11
to Spock Framework - User
Dah! Thanks
Reply all
Reply to author
Forward
0 new messages