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

org.jetbrains.spek.subject.Shared.kt Maven / Gradle / Ivy

There is a newer version: 1.1.5
Show newest version
package org.jetbrains.spek.subject

import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.Spec
import org.jetbrains.spek.api.include
import org.jetbrains.spek.api.lifecycle.CachingMode
import org.jetbrains.spek.api.lifecycle.LifecycleAware
import org.jetbrains.spek.meta.Experimental
import org.jetbrains.spek.subject.dsl.SubjectDsl
import org.jetbrains.spek.subject.dsl.SubjectProviderDsl
import kotlin.reflect.KProperty

@Experimental
infix fun  SubjectDsl.itBehavesLike(spec: SubjectSpek) {
    include(Spek.wrap {
        val value: SubjectProviderDsl = object: SubjectProviderDsl, Spec by this {
            val adapter = object: LifecycleAware {
                override fun getValue(thisRef: Any?, property: KProperty<*>): T {
                    return this()
                }

                override fun invoke(): T {
                    return [email protected]().invoke()
                }

            }

            override fun subject() = adapter
            override fun subject(mode: CachingMode, factory: () -> T) = adapter
            override val subject: T
                get() = adapter()

        }
        spec.spec(value)
    })
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy