Reputation: 1185
Geb Groovy and spock gurus, could you please help me understand why the following code doesn't work for me ( the variable 'closr' gives a null value)
import geb.Browser
import spock.lang.Specification
class somclass extends Specification{
def clos = {
go()
}
def Browser driveit(Browser browser, Closure script) {
script.setDelegate(browser)
script()
browser
}
}
objnew = new somclass()
def closr = objnew.clos
objnew.driveit(new Browser(),closr)
While
import geb.Browser
class somclass {
def clos = {
go()
}
def Browser driveit(Browser browser, Closure script) {
script.setDelegate(browser)
script()
browser
}
}
objnew = new somclass()
def closr = objnew.clos
objnew.driveit(new Browser(),closr)
this one does work for me( variable 'closr' has the closure returned ).? The only difference in the second one was I removed extending spock specification
Upvotes: 1
Views: 706
Reputation: 123920
I don't know what you are trying to achieve with this code, but Spock can't be used in this way. Spock specifications have to be executed via JUnit, and they have to conform to certain rules (e.g. test methods have blocks like setup:
or expect:
).
Upvotes: 1