【问题标题】:Grails 2.2.3 Can't Find Spock on ClasspathGrails 2.2.3 在类路径上找不到 Spock
【发布时间】:2013-10-11 14:07:22
【问题描述】:

我刚刚将 spock 添加到 Grails 2.2.3 项目中

  1. 我在 Buildonfig.groovy 中添加了以下依赖项:

    plugins {
        test(":spock:0.7")
    }
    
  2. 然后创建我的规范类,"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

【问题讨论】:

    标签: grails spock


    【解决方案1】:

    去吧! 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" }
      }
    }
    

    【讨论】:

    • 你之前没有在文档中找到这个吗?
    • @Abdullah 是的,这正是我找到它的地方。我在答案中引用了文档,然后取笑自己没有遵循古老的建议:R.T.F.M(阅读精美手册):)
    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 2013-12-17
    • 2016-02-04
    • 2017-09-12
    • 2014-05-29
    • 2013-07-22
    • 1970-01-01
    相关资源
    最近更新 更多