2

Grails 2.2.3 プロジェクトに spock を追加しました

  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
4

1 に答える 1

3

ダープ!RTFM

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" }
  }
}
于 2013-10-11T14:07:22.720 に答える