jem
02/12/2024, 7:05 AM"should foo" {
TestApplication().execute {
someFake.bar() shouldBe false
someOtherFake.baz() shouldBe true
}
}
Where TestApplication contains the fakes and suspend fun execute(f: suspend TestApplication.() -> Unit) = f(), so that the body has access to any fake it needs.
I'd like to get to
"should foo" {
someFake.bar() shouldBe false
someOtherFake.baz() shouldBe true
}
But I'm finding it very difficult to extend or configure the test to permit this.
Is this kind of thing supported/possible?LeoColman
02/12/2024, 11:57 AMLeoColman
02/12/2024, 11:57 AMLeoColman
02/12/2024, 11:57 AMbeforeSpec and afterSpec for exampleLeoColman
02/12/2024, 11:59 AMextension.someFake.bar(), but it's close enough IMOjem
02/12/2024, 11:57 PMextension, but it lead me to this solution.
private val apps = ConcurrentHashMap<Descriptor.TestDescriptor, TestApplication>()
/** Enables `app` in any test to create or get an instance of TestApplication for that test case */
val <http://StringSpecScope.app|StringSpecScope.app>: TestApplication
get() = apps.getOrPut(this.testCase.descriptor) {
TestApplication(this.testCase.descriptor)
}
}