2013-10-11 53 views
2
查找斯波克

我只是增加斯波克到一個Grails 2.2.3項目Grails的2.2.3無法在類路徑

  1. 我添加以下依賴於Buildonfig.groovy

    plugins { 
        test(":spock:0.7") 
    } 
    
  2. 然後創建了規範類,「測試/單元/ 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 

回答

4

DERP! R.T.F.M.

http://grails.org/plugin/spock

的Grails 2.2使用Groovy的2.0,它需要特殊的斯波克 版本。因此,要使用斯波克插件使用Grails 2.2,修改你 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" } 
    } 
} 
+2

你有沒有發現,在DOC這點。 – Abs

+0

@Abdullah是的,那正是我找到它的地方。我在答案中引用了這些文檔,然後對自己進行了一些探索,以便不遵循古老的建議:R.T.F.M(閱讀精細手冊):) – 10GritSandpaper