从Spock规范中提取规范

时间:2012-12-03 20:03:44

标签: grails spock

有没有办法从我在文件中打印的Spock测试中获取规范(过滤代码)?

例如,对于以下规范:

class CarSpec extends IntegrationSpec {

    def 'it should not retrieve deleted cars'() {
        given: 'a car'
            def car = new Car(uniqueName: 'carName')
            car.save()
        when: 'I delete the car'
            car.delete()
        then: 'it shouldn't find me the car on the DB'
            Car.find { uniqueName == 'carName' } == null
    }
}

应该打印如下:

CarSpec
    it should not retrieve deleted cars
        given a car
        when I delete the car
        then it shouldn't find me the car on the DB

1 个答案:

答案 0 :(得分:4)

您可以使用其中一个可用的第三方插件(例如https://github.com/damage-control/report),或编写您自己的Spock扩展程序(请参阅https://github.com/spockframework/smarter-testing-with-spock/tree/master/src/test/groovy/extension/custom)。