Filip Piechowski
04/13/2022, 9:40 AMTestFactory
builder, that would nest further steps declared by user in a lambda as the last parameter of my test factory.
In my specific case that would look like this:
class MySpec : FreeSpec({
include(replicatorSpec(...) { // this: ReplicatorTestFactoryConfiguration extending TestFactoryConfiguration(), FreeSpecRootScope
parent(...) { // this: ReplicatorTestFactoryConfiguration.AfterParent extending TestFactoryConfiguration(), FreeSpecRootScope
create(...) { // this: ReplicatorTestFactoryConfiguration.AfterCreate extending TestFactoryConfiguration(), FreeSpecRootScope
update(...)
}
}
)}
})
inline fun RootScope.replicatorSpec(
...,
crossinline configure: ReplicatorTestFactoryConfiguration.() -> Unit = { }
) = freeSpec {
<http://logger.info|logger.info> { "replicatorSpec" }
beforeSpec {...}
val configuration = ReplicatorTestFactoryConfiguration(...)
configuration.configure()
afterSpec {...}
}
inline fun ReplicatorTestFactoryConfiguration.parent(
... ,
crossinline then: ReplicatorTestFactoryConfiguration.AfterParent<P>.() -> Unit = {}
) { ... }
inline fun ReplicatorTestFactoryConfiguration.AfterParent.create(
... ,
crossinline then: ReplicatorTestFactoryConfiguration.AfterParent<P>.AfterCreate<P, COUT>.() -> Unit = { }
) { ... }
inline fun ReplicatorTestFactoryConfiguration.AfterParent.AfterCreate.update(...) { ... }
But when running tests and putting debug FreeSpec test scopes ("debug" - { }
) i see that execution gets only to the replicatorSpec(...)
and the FreeSpecScopes defined in there, but anything further like the code defined in lambda. How can I create such asam
04/13/2022, 9:49 AMFilip Piechowski
04/13/2022, 9:54 AMsam
04/13/2022, 10:02 AMclass WildFactories : FreeSpec() {
init {
include(replicatorSpec {
parent {
"foo1" - {
"bar1" {
1 shouldBe 1
}
}
}
})
"foo2" - {
"bar2" {
1 shouldBe 1
}
}
}
}
class ReplicatorTestFactoryConfiguration(val c: FreeSpecTestFactoryConfiguration) : TestFactoryConfiguration(),
FreeSpecRootScope
fun replicatorSpec(configure: ReplicatorTestFactoryConfiguration.() -> Unit) = freeSpec {
val configuration = ReplicatorTestFactoryConfiguration(this)
configuration.configure()
}
fun ReplicatorTestFactoryConfiguration.parent(context: FreeSpecTestFactoryConfiguration.() -> Unit) {
this.c.context()
}
sam
04/13/2022, 10:02 AMFilip Piechowski
04/13/2022, 12:26 PMFreeSpecTestFactoryConfiguration.() -> Unit
while I need it to be ReplicatorTestFactoryConfiguration
because i store state in this class. eventually i can store the stare in parameters inside ( … )
but it look cleaner with it sitting in this
contextsam
04/13/2022, 12:31 PMsam
04/13/2022, 12:32 PM