我刚刚将spock添加到Grails 2.2.3项目中
我将以下依赖项添加到 Buildonfig.groovy :
plugins {
test(":spock:0.7")
}
然后创建了我的规范类,“test / unit / LocationSpec.groovy :
import grails.test.mixin.*
import org.junit.*
import spock.lang.*
/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(Location)
class LocationSpec extends Specification {
def setup() {
}
def cleanup() {
}
def "compare"() {
when:
def loc1 = new Location(description:descr1)
def loc2 = new Location(description:descr2)
then:
loc1.compareTo(loc2) == descr1.compareTo(descr2)
where:
descr1 | descr2 | pidm1 | pidm2
"foo" | "foo" | 1333868 | 1333868
}
}
但是我在规范导入行中遇到以下错误:
Groovy:unable to resolve class spock.lang.Specification
答案 0 :(得分:3)
DERP!的 R.T.F.M。强>
来自http://grails.org/plugin/spock:
Grails 2.2使用Groovy 2.0,它需要一个特殊的Spock 版。所以要使用Grails 2.2的Spock插件,修改你 BuildConfig.groovy文件包含以下内容:
grails.project.dependency.resolution = {
repositories {
grailsCentral()
mavenCentral()
}
dependencies {
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
}
plugins {
test(":spock:0.7") { exclude "spock-grails-support" }
}
}