I want to write a Spek test in Kotlin. The test should read an HTML file from the src/test/resources folder. How to do it?
class MySpec : Spek({
No idea why this is so hard, but the simplest way I've found (without having to refer to a particular class) is:
fun getResourceAsText(path: String): String {
return object {}.javaClass.getResource(path).readText()
}
And then passing in an absolute URL, e.g.
val html = getResourceAsText("/www/index.html")