tutteli-spek-extensions

A set of Spek extensions

License

License

GroupId

GroupId

ch.tutteli.spek
ArtifactId

ArtifactId

tutteli-spek-extensions
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

tutteli-spek-extensions
A set of Spek extensions
Project URL

Project URL

https://github.com/robstoll/tutteli-spek-extensions
Source Code Management

Source Code Management

https://github.com/robstoll/tutteli-spek-extensions

Download tutteli-spek-extensions

How to add to project

<!-- https://jarcasting.com/artifacts/ch.tutteli.spek/tutteli-spek-extensions/ -->
<dependency>
    <groupId>ch.tutteli.spek</groupId>
    <artifactId>tutteli-spek-extensions</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/ch.tutteli.spek/tutteli-spek-extensions/
implementation 'ch.tutteli.spek:tutteli-spek-extensions:1.2.1'
// https://jarcasting.com/artifacts/ch.tutteli.spek/tutteli-spek-extensions/
implementation ("ch.tutteli.spek:tutteli-spek-extensions:1.2.1")
'ch.tutteli.spek:tutteli-spek-extensions:jar:1.2.1'
<dependency org="ch.tutteli.spek" name="tutteli-spek-extensions" rev="1.2.1">
  <artifact name="tutteli-spek-extensions" type="jar" />
</dependency>
@Grapes(
@Grab(group='ch.tutteli.spek', module='tutteli-spek-extensions', version='1.2.1')
)
libraryDependencies += "ch.tutteli.spek" % "tutteli-spek-extensions" % "1.2.1"
[ch.tutteli.spek/tutteli-spek-extensions "1.2.1"]

Dependencies

runtime (3)

Group / Artifact Type Version
org.spekframework.spek2 : spek-dsl-jvm jar 2.0.15
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.21-2
org.jetbrains.kotlin : kotlin-reflect jar 1.4.21-2

Project Modules

There are no modules declared in this project.

Download Apache license Build Status Ubuntu Build Status Windows SonarCloud Status SonarCloud Coverage

Tutteli spek extension

A set of Spek extensions such as MemoizedTempFolder.

Installation

gradle

repositories {
    mavenCentral()

    // or
    // jcenter()

    // or the following repo    
    // maven {
    //     url  "https://dl.bintray.com/robstoll/tutteli-jars" 
    // }
}

dependencies {
    testImplementation 'ch.tutteli.spek:tutteli-spek-extensions:1.2.1'
}

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 memoizedTempFolder
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 ch.tutteli.atrium.api.fluent.en_GB.jdk8.*
import ch.tutteli.atrium.verbs.expect
import memoizedTempFolder
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 ch.tutteli.atrium.api.fluent.en_GB.*
import ch.tutteli.atrium.verbs.expect
import memoizedTempFolder
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 = newDirectory("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: newDirectory, newSymbolicLink, resolves and withinTmpDir.

Tutteli spek extension works best in combination with Niok which enhances Path with methods like createDirectories, setAttribute, writeLines and many more (not only useful in tests but also in production code). With Niok in place, more complicated setup can be defined easily:

import memoizedTempFolder
import ch.tutteli.niok.*
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) {
            withinTmpDir {
                val subDir = resolve("dir1/dir2/dir3").createDirectories()
                subDir.resolve("a.txt").writeLines(listOf("a", "b", "c"))
            }
        }
    }
})

And if you like to assert certain properties of a Path, then we recommend using Atrium.

License

tutteli-spek-extensions is licensed under Apache 2.0.

Versions

Version
1.2.1
1.1.0