All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oneeyedmen.konsent.acceptance-testing.kt Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.oneeyedmen.konsent

import com.natpryce.hamkrest.MatchResult
import com.natpryce.hamkrest.Matcher

fun  Given(actor: Actor, function: Steps.() -> Unit) = function.invoke(givenSteps(actor))
fun  Given(actor: Actor) = givenSteps(actor)

fun  When(actor: Actor, function: Steps.() -> Unit) = function.invoke(whenSteps(actor))
fun  When(actor: Actor) = whenSteps(actor)

fun  Then(actor: Actor, function: Steps.() -> Unit) = function.invoke(thenSteps(actor))
fun  Then(actor: Actor) = thenSteps(actor)

fun  Steps.shouldSee(selector: Selector, matcher: Matcher) {
    val matchResult = matcher.invoke(selector.select(actor))
    val resultString = when(matchResult) {
        is MatchResult.Mismatch -> "[expected ${matcher.description}, ${matchResult.description}]"
        else -> matcher.description
    }
    record("sees", selector.description, resultString)
}

class Steps(val actor: Actor, val driver: DriverT, val recorder: FeatureRecorder, private val term: String?) {
    fun describedBy(stepName: String, block: Steps.() -> Unit) {
        record(stepName)
        block()
    }
    fun record(vararg args: Any) = recorder.term(term, actor.name, *args)

}

fun  anonymousSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, null)
fun  givenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "Given")
fun  whenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "When")
fun  thenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "Then")





© 2015 - 2024 Weber Informatics LLC | Privacy Policy