thanneeruvenu / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Grails tests cannot use project classes in SpockConfig #184

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When compiling a SpockConfig file in a Grails project, classes in the project 
code are not visible.  Classes from the project dependencies can be used.

- Define an annotation class under project src/groovy: myproj.util.Smoke
- Define a file test/SmokeConfig.groovy containing:

  import myproj.util.Smoke

  runner {
      include Smoke
  }

- Run grails -Dspock.configuration=test/SmokeConfig.groovy test-app 
functional:spock

- Fails with the stack trace:
spock.config.ConfigurationException: Error compiling configuration script 
'test/SmokeConfig.groovy'
    at org.spockframework.runtime.ConfigurationScriptLoader.loadScriptFromFileSystemLocation(ConfigurationScriptLoader.java:117)
    at org.spockframework.runtime.ConfigurationScriptLoader.loadScriptFromSystemPropertyInducedLocation(ConfigurationScriptLoader.java:93)
    at org.spockframework.runtime.ConfigurationScriptLoader.loadAutoDetectedScript(ConfigurationScriptLoader.java:58)
    at org.spockframework.runtime.RunContext.createBottomContext(RunContext.java:147)
    at org.spockframework.runtime.RunContext.get(RunContext.java:129)
    at org.spockframework.runtime.SpecUtil.getConfiguration(SpecUtil.java:101)
    at org.spockframework.runtime.SpecUtil$getConfiguration.call(Unknown Source)
    at grails.plugin.spock.test.GrailsSpecTestType.optimizeSpecRunOrderIfEnabled(GrailsSpecTestType.groovy:73)
    at grails.plugin.spock.test.GrailsSpecTestType.this$3$optimizeSpecRunOrderIfEnabled(GrailsSpecTestType.groovy)
    at grails.plugin.spock.test.GrailsSpecTestType$this$3$optimizeSpecRunOrderIfEnabled.callCurrent(Unknown Source)
    at grails.plugin.spock.test.GrailsSpecTestType.doPrepare(GrailsSpecTestType.groovy:58)
    at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:261)
    at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
    at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
    at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
    at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
    at TestApp$_run_closure1.doCall(TestApp.groovy:82)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)

Versions:
 Spock 0.5-groovy-1.7
 Grails 1.3.7
 Groovy 1.7.8
 geb-spock-0.5.1

The same thing happens if you try to use a base class from the project with the 
include.  If you use an annotation or base class from any of the project 
dependencies, it compiles successfully.

Original issue reported on code.google.com by booco...@gmail.com on 2 Jun 2011 at 4:58

GoogleCodeExporter commented 8 years ago
same problem on Grails 2.2.4, Groovy 2.0.8, spock-core-0.7-groovy-2.0

Original comment by jdbeu...@gmail.com on 15 Nov 2013 at 10:02

GoogleCodeExporter commented 8 years ago
Same problem on Grails 2.3.2 too.

I've submitted a pull request for a fix:
https://github.com/spockframework/spock/pull/24

Original comment by jdbeu...@gmail.com on 22 Nov 2013 at 2:49

GoogleCodeExporter commented 8 years ago
Just to confirm that I see this on Grails 2.3.7 as well.

The work-around given here works:

http://spock-framework.3207229.n2.nabble.com/Include-Exclude-using-SpockConfig-t
d6431180.html

I settled on:

///
import javax.annotation.Resource as Slow

@Slow
class MySpec extends GebReportingSpec {
///

Because Resource is a class-level annotation.

Would LOVE to see this fixed up.

Original comment by googlegr...@transentia.com.au on 12 Apr 2014 at 11:15

GoogleCodeExporter commented 8 years ago
I used my pull request 24 version of Spock with Grails 2.2, but since Grails 
2.3 comes with its own version of Spock, I had to use a different approach.  
Instead of using a Spock config to include a certain annotation, I implemented 
an IGlobalExtension to exclude all the specs without that annotation.

Original comment by jdbeu...@gmail.com on 13 Apr 2014 at 1:01

GoogleCodeExporter commented 8 years ago
I don't see this issue on Grails 3.0.2 or 3.0.3. They use 
spock-core:1.0-groovy-2.4, but apparently load SpockConfig.groovy with a 
classpath that includes classes under src/test and src/main.

Original comment by jdbeu...@gmail.com on 13 Jul 2015 at 8:43