1

Geb Groovy 和 spock 大师,您能帮我理解为什么下面的代码对我不起作用(变量 'closr' 给出一个空值)

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)

尽管

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)

这个对我有用(变量'closr'返回了闭包)。?第二个的唯一区别是我删除了扩展 spock 规范

4

1 回答 1

1

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

于 2013-02-01T12:58:18.183 回答