Maybe some sort of extension function
# kotest
l
Maybe some sort of extension function
a
that would be good - but I can’t see the listener in the context so I don’t think it can be retrieved
l
You could add an extension to Spec
a
I’ve tried looking but during debug I couldn’t find the container listener listed anywhere - do you know a method that could retrieve it?
here’s how it’s registered
Copy code
class KotestConfig : AbstractProjectConfig() {
  override fun listeners(): List<Listener> =
    listOf(testContainer.perSpec())
}
I know it works because the tests work
d
Maybe
defaultConfig.listeners
in any TestScope?
Maybe search for it there and cast it back to the instance you need.
a
I’ve tried looking through loads of methods while debugging and couldn’t see any listener
maybe it’s in there somewhere but debugging this many nested lambdas is really difficult
d
Or just save it as a global lazy val in ProjectConfig and refer to it from there? The listener instance is the same, it just starts and stops the containers every test...
a
I’m working on setting something like that up. I just hoped there was an included solution for passing variables into Specs based on config
s
I would do somthing along the lines of what Dave suggests. Make the listener a val in your config. It doesn't even need to be lazy.
Copy code
object GlobalConfig : AbstractProjectConfig() {
   val testContainer = ...
   override fun listeners(): List<Listener> {
      return listOf(testContainer.perSpec())
   }
}
Then you can just do
GlobalConfig.testContainer
Note that the config is an object here, not a class
The container itself still won't be started/stopped until each spec is created