Description
Try the following script in groovy console
import spock.lang.* @Grab(group='org.spockframework', module='spock-core', version='0.2') class HelloSpock extends Specification { def "can you figure out what I'm up to?"() { expect: name.size() == length where: ignored = println ("where: \n p0=$p0\n p1=$p1") name << ["Kirk", "Spock", "Scotty"] length << [4, 5, 6] } }
Output:
JUnit 4 Runner, Tests: 1, Failures: 1, Time: 0 Test Failure: initializationError(HelloSpock) org.spockframework.runtime.InvalidSpeckError: Class 'HelloSpock' is not a Speck, or has not been compiled properly at org.spockframework.runtime.SpeckInfoBuilder.getSpeckMetadata(SpeckInfoBuilder.java:66) at org.spockframework.runtime.SpeckInfoBuilder.build(SpeckInfoBuilder.java:46) at spock.lang.Sputnik.<init>(Sputnik.java:38) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ....
This is happening because spock works by ASTTransformation and before @Grab(spock) has brought spock jar on groovy classpath, groovy does not see its AST transforms and hence the class does not undergo spock related AST transformation and does not run as a spock test.
However, from the 2nd run onwards, it runs from the same console because in the 2nd run, when groovy scans for AST transforms, it finds spock jar also on the classpath and its AST transformation happens and the class runs as a spock test.
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-3851 @Grapes does not work (at least not in Groovy Console)
- Closed