bbaldino
07/09/2020, 7:53 PMcontext("when the server") {
withTestApplication({
myServerModule()
}) {
context("receives a request for url/to/something") {
with(handleRequest(<http://HttpMethod.Post|HttpMethod.Post>, "url/to/som ething") {
should("return the correct response") {
response.status() shouldBe HttpStatusCode.OK
}
}
}
}
}
This doesn't work though, as where should
is there isn't a coroutine scope and it complains. Is there a better way to do tests like this? Or would it be possible to have a non-suspend version of should
?runBlocking
in the meantime, but that feels a bit hackysam
07/09/2020, 7:59 PMbbaldino
07/09/2020, 7:59 PMsam
07/09/2020, 8:00 PMbbaldino
07/09/2020, 8:00 PMsam
07/09/2020, 8:00 PMcontext("when the server") {
withTestApplication({
myServerModule()
}) {
context("receives a request for url/to/something") { context ->
with(handleRequest(<http://HttpMethod.Post|HttpMethod.Post>, "url/to/som ething") {
context.should("return the correct response") {
response.status() shouldBe HttpStatusCode.OK
}
}
}
}
}
LeoColman
07/09/2020, 8:03 PMwith
and should
bbaldino
07/09/2020, 8:03 PMLeoColman
07/09/2020, 8:04 PMwith
bbaldino
07/09/2020, 8:06 PMhandleRequest
rather than using with
withTestApplication
lambda is a receiversam
07/09/2020, 8:09 PMbbaldino
07/09/2020, 8:10 PMshould
?sam
07/09/2020, 8:10 PMbbaldino
07/09/2020, 8:11 PMShouldSpecContextScope.kt
should
function there which just calls the suspend one inside of runBlocking
sam
07/09/2020, 8:18 PMbbaldino
07/09/2020, 8:18 PMsam
07/09/2020, 8:18 PMfun should(name: String) =
TestWithConfigBuilder(TestName("should ", name), testContext, defaultConfig, xdisabled = false)
fun xshould(name: String) =
TestWithConfigBuilder(TestName("should ", name), testContext, defaultConfig, xdisabled = true)
bbaldino
07/09/2020, 8:18 PMcoroutineScope
would do itsam
07/09/2020, 8:18 PMshould("name").config() { }
bbaldino
07/09/2020, 8:19 PM"into the second call"what do you mean?
ContainerScope#addTest
need to be suspend?registerTestCase
needs to be suspendsam
07/09/2020, 8:22 PMbbaldino
07/09/2020, 8:22 PMsam
07/09/2020, 8:22 PMbbaldino
07/09/2020, 8:26 PMcontext("some test") test@ {
and then doing this@test.should
doesn't work eithersam
07/09/2020, 8:27 PMval context = this
bbaldino
07/09/2020, 8:28 PMsam
07/09/2020, 8:29 PMcontext("when the server") {
val c1 = this
withTestApplication({
myServerModule()
}) {
c1.context("receives a request for url/to/something") {
with(handleRequest(<http://HttpMethod.Post|HttpMethod.Post>, "url/to/som ething") {
should("return the correct response") {
response.status() shouldBe HttpStatusCode.OK
}
}
}
}
}
bbaldino
07/09/2020, 8:30 PMcontext
has to be called within a coroutine 😕sam
07/09/2020, 8:33 PMbbaldino
07/09/2020, 8:34 PM