mattyway / tutteli-spek-extensions

Extensions for the spek framework such as TempFolder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Download Apache license Build Status Travis Build status GitHub Actions SonarCloud Status SonarCloud Coverage

Tutteli spek extension

A set of Spek extensions such as MemoizedTempFolder.

Installation

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).

Features

MemoizedTempFolder

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.

License

tutteli-spek-extensions is licensed under Apache 2.0.

About

Extensions for the spek framework such as TempFolder

License:Apache License 2.0


Languages

Language:Kotlin 62.2%Language:Shell 26.3%Language:Batchfile 10.8%Language:Java 0.7%