A set of Spek extensions such as MemoizedTempFolder.
gradle
repositories {
jcenter()
// or the following repo
//maven {
// url "https://dl.bintray.com/robstoll/tutteli-jars"
//}
}
dependencies {
testImplementation 'ch.tutteli.spek:tutteli-spek-extensions:1.0.1'
}
Use tutteli-spek-extensions-android
in case you deal with android (does not contain a module-info.java which d8 cannot cope with).
memoizedTempFolder
provides -- similar to TemporaryFolder in junit4 -- utility methods to create temp files and folders and takes care of deleting them.
Specify a memoizedTempFolder
within a group like scope near to the test you are going to use the tempFolder (default CachingMode
is per TEST
, so each test gets its own temporary directory)
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object MySpec: Spek({
describe("...") {
val tempFolder by memoizedTempFolder()
it ("...") {
val file = tempFolder.newFile("test.txt")
}
}
})
Pass a CachingMode
if required (see Caching modes @ spekframework.org)
For instance:
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.spekframework.spek2.lifecycle.CachingMode
object MySpec: Spek({
describe("...") {
val tempFolder by memoizedTempFolder(CachingMode.SCOPE)
it ("test1") {
val file = tempFolder.newFile("test.txt")
file.delete()
}
it("test2"){
expect(file).exists() // would fail
}
}
})
And you can use the second argument of memoizedTempFolder
for additional setup:
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.spekframework.spek2.lifecycle.CachingMode
object MySpec: Spek({
describe("...") {
val tempFolder by memoizedTempFolder(CachingMode.TEST) {
val f = newFolder("folderWithinTempFolder")
newSymbolicLink("link", f)
}
it ("test1") {
expect(tempFolder.resolve("folderWithinTempFolder")).exists()
expect(tempFolder.resolve("link")).exists()
}
}
})
There are a few other utility methods defined on MemoizedTempFolder
: newFolder
, newSymbolicLink
and resolves
Please open an issue if you want more or create a pull request.
In case you want to operate on Path
we recommend using Niok and
for assertions use Atrium with the jdk8 extension.
tutteli-spek-extensions is licensed under Apache 2.0.