-
-
Save ysb33r/5825457 to your computer and use it in GitHub Desktop.
class Example { | |
def hhg() { 42 } | |
} | |
import spock.lang.* | |
class ExampleSpec extends Specification { | |
def "It must be 42" () { | |
def ex = new Example() | |
expect: | |
ex.hhg() == 6*9 | |
} | |
} |
import static org.junit.Assert.* | |
import org.junit.* | |
class ExampleTest { | |
@Test | |
void isIt42() { | |
def ex = new Example() | |
assertTrue ex.hhg() == 6*9 | |
} | |
} |
# Compile the groovy code | |
groovyc *.groovy | |
# Running a JUnit4 test | |
java -cp $GROOVY_HOME/embeddable/groovy-all-2.1.4.jar:$GROOVY_HOME/lib/junit-4.11.jar:$GROOVY_HOME/lib/hamcrest-core-1.3.jar:. \ | |
org.junit.runner.JUnitCore ExampleTest | |
# Download Spock if you don't have it | |
grape install org.spockframework spock-core 0.7-groovy-2.0 | |
# Running a Spock class | |
java -cp ~/.grapes/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar:$GROOVY_HOME/embeddable/groovy-all-2.1.4.jar:$GROOVY_HOME/lib/junit-4.11.jar:$GROOVY_HOME/lib/hamcrest-core-1.3.jar:. \ | |
org.junit.runner.JUnitCore ExampleSpec |
Add this to your spec:
@Grab('org.spockframework:spock-core:2.0-M2-groovy-3.0')
@GrabExclude('org.codehaus.groovy:*')
Then just run (I used 3.0.3):
> groovy ExampleSpec
You can also run your test directly (without change or classpath setup):
> groovy ExampleSpec
And you might consider replacing assertTrue
with just assert
for an improved power assert error message in your JUnit test.
Thanks Paul.
Does @grab try to pull the jar over the network?
If so then its not an option since this is all running inside a docker container with no network access.
I can't see any difference between your two groovy
calls...?
Is there a way Groovy can find the names of the Spec classes by itself?
I'd prefer it if it still worked if people changed the names of their Spec classes.
@grab doesn't have to use a network if you have some local cache/repo. You can also add spock jar(s) to a ${user.home}/.groovy/lib or ${groovy.home}/lib directory.
Ok. Thanks. I now have something that works.
groovyc *.groovy
if [ $? -eq 0 ]; then
groovy HikerSpec
fi
But it still hard-wires the name HikerSpec.
Do you know if that can be fixed?
@JonJagger I'll see if I can get around to this on the weekend.