leonard84 on master
Bump org.gradle.test-retry from… (compare)
leonard84 on gradle
leonard84 on gradle
Bump org.gradle.test-retry from… (compare)
github-actions[bot] on gh-pages
Publish javadoc/2.2-SNAPSHOT (compare)
class ClosureTest extends Specification {
Helper helper = new Helper()
void "testy"() {
expect:
verify.call()
}
}
class Helper {
Closure verify= { assert 1 == 2 }
}
runner {
parallel {
enabled true
defaultSpecificationExecutionMode ExecutionMode.SAME_THREAD
defaultExecutionMode ExecutionMode.SAME_THREAD
}
}
DESKTOP-CIDB3LU MINGW64 /e/projects/spock (master)
$ ./gradlew spock-core:test
Configure project :spock-core
[versioning] WARNING - the working copy has unstaged or uncommitted changes.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 up-to-date
A build scan was not published as you have not authenticated with server 'ge.spockframework.org'.
--no-build-cache
, or change some code locally
[[1,2,3], [4,5,6]].combinations()
# [[1, 4], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [1, 6], [2, 6], [3, 6]]
[[1,2,3], [4,5,6]].combinations().sort()
# [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]]
[3, [1], [2], 1, [1,2], [1,1], [1,2,3], [1,2], 2, [1,2,2], [3]].sort()
# [1, 2, 3, [1], [2], [3], [1, 1], [1, 2], [1, 2], [1, 2, 2], [1, 2, 3]]
Hi all, I have a newbie question about Script bindings... I am running a test via the EmbeddedSpecRunner()
import spock.util.EmbeddedSpecRunner
def esr = new EmbeddedSpecRunner()
esr.runClass(SpockTestClass.class)
This is my groovy Script class. Before I run my Script I bind an instance of a class called myDsl
to it.
I would like to use myDsl
from within SpockTestClass but cannot figure out a way to supply it via the EmbeddedSpecRunner
I have tried creating a @Singleton and referencing it from within the Specification but I'm guessing classloaders stop me seeing this externally created .instance
How can I supply a pre-built Object(s) for use within a Specification?
@kriegaex, thank you for looking at this... the code snippet is an instance of the Groovy Script
class which has a set/get Binding method (https://docs.groovy-lang.org/latest/html/api/groovy/lang/Script.html) Before I run the Script I add an object called myDsl via a Binding
(https://docs.groovy-lang.org/latest/html/api/groovy/lang/Binding.html). For example, myDsl has a log() method so I can do this:
import spock.util.EmbeddedSpecRunner
def esr = new EmbeddedSpecRunner()
myDsl.log("About to run the test")
esr.runClass(SpockTestClass.class)
However I cannot access the Binding of the Script from within my SpockTestClass as I cannot find a way to pass any pre-instantiated object into a test when using the EmbeddedSpecRunner(). I think the Binding
is perhaps confusing my question. A simpler question might be :
import spock.util.EmbeddedSpecRunner
def esr = new EmbeddedSpecRunner()
def myMap = [:]
myMap['hello'] = 'world'
esr.runClass(SpockTestClass.class)
The test class looks like:
import spock.lang.*
class SpockTestClass extends Specification {
def "hello must be world"() {
given:
def value = myMap['hello']
expect:
value == 'world'
}
}
The results are:
groovy.lang.MissingPropertyException: No such property: myMap for class: io.platform6.app.core.scripts.rd_spockmain.SpockTestClass
at SpockTestClass.hello must be world(SpockTestClass:10)
How can I supply a pre-built Object(s) for use within a Specification?
Ugh, that's ugly, depending on a binding not present in the spec itself during feature execution. But I understand what you are trying to do. I know that my recommendation not to do it like that, because the test also cannot run stand-alone like that and forever depends on the calling script, does not solve your problem. The Groovy guys like Leonard and Björn probably know if and how this can be achieved.
My recommendation would be to fetch the values you need in a where:
block, maybe using a custom data provider. You can read them from a file, a database, a website or wherever.