Skip to content

Commit

Permalink
Merge pull request #1 from jfaissolle/master
Browse files Browse the repository at this point in the history
Spock integration tests support
  • Loading branch information
longwa committed Jul 13, 2012
2 parents 8b78714 + fbb7c2f commit ef904a2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions GuardGrailsPlugin.groovy
Expand Up @@ -8,6 +8,8 @@ class GuardGrailsPlugin {
// the other plugins this plugin depends on
def dependsOn = [:]

def loadAfter = ['spock']

// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
Expand Down
3 changes: 3 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Expand Up @@ -21,5 +21,8 @@ grails.project.dependency.resolution = {
build(":tomcat:$grailsVersion", ":release:2.0.3") {
export = false
}
test(":spock:0.6") {
export = false
}
}
}
9 changes: 9 additions & 0 deletions scripts/_Events.groovy
Expand Up @@ -2,11 +2,20 @@ import org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType
import org.codehaus.groovy.grails.test.support.GrailsTestMode

guardTests = []
guardSpock = false


loadGuardTestTypes = {
phasesToRun << "guard"
def mode = new GrailsTestMode(autowire: true, wrapInTransaction: true, wrapInRequestEnvironment: true)
guardTests << new JUnit4GrailsTestType("guard", "integration", mode)

// if spock is loaded
if (binding.variables.containsKey("loadSpecTestTypeClass")) {
def specTestTypeClass = loadSpecTestTypeClass()
guardSpock = true
guardTests << specTestTypeClass.newInstance('spock', 'integration')
}
}

// Guard testing uses the same startup as integration
Expand Down
13 changes: 11 additions & 2 deletions scripts/_Guard.groovy
Expand Up @@ -17,7 +17,7 @@ target(watchForTestChanges: "Watch for changes") {
grailsConsole.addStatus "--------------------------------------------------------------------"

GuardFileChangeListener listener = registerReloadingListener()
watchLoop(listener)
watchLoop(listener, guardSpock)
}
else {
grailsConsole.error "Reloading agent not enabled, try running grails with the -reloading flag as the first argument"
Expand All @@ -44,7 +44,7 @@ GuardFileChangeListener registerReloadingListener() {
/**
* Main watch loop
*/
def watchLoop(GuardFileChangeListener listener) {
def watchLoop(GuardFileChangeListener listener, spock) {
//noinspection GroovyInfiniteLoopStatement
while(true) {
def changes = listener.consumeChanges()
Expand Down Expand Up @@ -73,9 +73,18 @@ def watchLoop(GuardFileChangeListener listener) {
def mode = new GrailsTestMode(autowire: true, wrapInTransaction: true, wrapInRequestEnvironment: true)
def guardTestType = new JUnit4GrailsTestType("guard", "integration", mode)


// Run the tests
currentTestPhaseName = "guard"
processTests(guardTestType)

// Run Spock tests
if (spock) {
def specTestTypeClass = classLoader.loadClass('grails.plugin.spock.test.GrailsSpecTestType')
def specTestType = specTestTypeClass.newInstance('spock', "integration")
processTests(specTestType)
}

currentTestPhaseName = null

grailsConsole.addStatus "Tests Complete"
Expand Down
17 changes: 17 additions & 0 deletions test/integration/guard/grails/SampleServiceSpec.groovy
@@ -0,0 +1,17 @@
package guard.grails
import grails.plugin.spock.IntegrationSpec

import spock.lang.*

class SampleServiceSpec extends IntegrationSpec {

def sampleService

def "injected sampleService is present"() {
when:
def msg = sampleService.helloWorld()

then:
msg == "Hello World!"
}
}

0 comments on commit ef904a2

Please sign in to comment.