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
?bbaldino
07/09/2020, 7:54 PMrunBlocking
in the meantime, but that feels a bit hackysam
07/09/2020, 7:59 PMsam
07/09/2020, 7:59 PMbbaldino
07/09/2020, 7:59 PMsam
07/09/2020, 8:00 PMsam
07/09/2020, 8:00 PMbbaldino
07/09/2020, 8:00 PMsam
07/09/2020, 8:00 PMsam
07/09/2020, 8:01 PMsam
07/09/2020, 8:01 PMsam
07/09/2020, 8:01 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
LeoColman
07/09/2020, 8:03 PMbbaldino
07/09/2020, 8:03 PMbbaldino
07/09/2020, 8:04 PMLeoColman
07/09/2020, 8:04 PMLeoColman
07/09/2020, 8:04 PMwith
LeoColman
07/09/2020, 8:05 PMbbaldino
07/09/2020, 8:06 PMbbaldino
07/09/2020, 8:07 PMhandleRequest
rather than using with
bbaldino
07/09/2020, 8:07 PMbbaldino
07/09/2020, 8:07 PMbbaldino
07/09/2020, 8:07 PMbbaldino
07/09/2020, 8:08 PMwithTestApplication
lambda is a receiversam
07/09/2020, 8:09 PMbbaldino
07/09/2020, 8:10 PMshould
?bbaldino
07/09/2020, 8:10 PMsam
07/09/2020, 8:10 PMbbaldino
07/09/2020, 8:11 PMShouldSpecContextScope.kt
bbaldino
07/09/2020, 8:11 PMbbaldino
07/09/2020, 8:12 PMshould
function there which just calls the suspend one inside of runBlocking
bbaldino
07/09/2020, 8:17 PMsam
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 PMsam
07/09/2020, 8:18 PMshould("name").config() { }
bbaldino
07/09/2020, 8:19 PM"into the second call"what do you mean?
bbaldino
07/09/2020, 8:19 PMbbaldino
07/09/2020, 8:21 PMContainerScope#addTest
need to be suspend?bbaldino
07/09/2020, 8:21 PMregisterTestCase
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 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 PMbbaldino
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 PMbbaldino
07/09/2020, 8:31 PMbbaldino
07/09/2020, 8:31 PMcontext
has to be called within a coroutine 😕sam
07/09/2020, 8:33 PMsam
07/09/2020, 8:34 PMbbaldino
07/09/2020, 8:34 PM