spockframework / spockframework/spock

Grails tests cannot use project classes in SpockConfig

Open
#306 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Defect
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 184

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.

Reported by boocockp on 2011-06-02 16:58:21

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ConfigurationScriptLoader and the GrailsSpecTestType.groovy call sites shown in the stack trace, then reproduce with the provided Smoke annotation, SmokeConfig.groovy, and Grails command. Done means a project class or annotation imported by test/SmokeConfig.groovy compiles successfully, while dependency classes continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.