alexfacciorusso
09/25/2020, 11:25 AMBehaviorSpec
. Since I need to perform some actions before the spec is initialised by using a custom Listener, but it doesn’t seem to work. Here’s an example:
class DashboardViewModelTest : BehaviorSpec({
listeners(
MyListener
)
// [I need a listener (or multiple listeners) to be executed immediately here]
val myClassUnderTest = MyClassUnderTest(...)
Given("Something") {...}
Given("Something else") {...}
// [And then I need the same listener to de-initialise my stuff here]
})
How can I have something like that?
Of course if I create a wrapping Given, for example, the listeners actually get triggered, but I was trying to avoid a further nesting level with something like Given(“My class initialised”), it seems redundant to me.wasyl
09/25/2020, 11:30 AMalexfacciorusso
09/25/2020, 11:32 AMalexfacciorusso
09/25/2020, 11:34 AMprepareSpec
function in TestListener
, but it seems to never be called when my spec starts (technically it should be called as soon as the listener is set to the spec itself, which doesn’t happen and might even be a potential bug)wasyl
09/25/2020, 12:02 PMfun TestConfiguration.tempDir(name: String = "temp-directory"): File =
Files.createTempDirectory(name).toFile().also { file ->
afterSpec { file.deleteRecursively() }
}
alexfacciorusso
09/25/2020, 2:38 PMwasyl
09/25/2020, 2:48 PMalexfacciorusso
09/25/2020, 3:04 PMwasyl
09/25/2020, 3:12 PMalexfacciorusso
09/25/2020, 3:14 PMwasyl
09/25/2020, 3:22 PMwasyl
09/25/2020, 3:22 PMwasyl
09/25/2020, 3:23 PMalexfacciorusso
09/25/2020, 3:25 PMprepareSpec
listener method should be called immediately when the listener is attached to the spec itself, or something like thatwasyl
09/25/2020, 3:29 PMalexfacciorusso
09/25/2020, 4:23 PMfalse
so to be retro-compatible. Of course then some logic would have to be added to take into account the lifecycle of the test etcwasyl
09/25/2020, 4:49 PMfun TestContext.addMyListener() {
doStuffNow()
afterSpec { /* cleanUp */ }