最終,我的目標是編寫一個自定義噴霧指令,供現有應用程序中的各種路徑使用。到目前爲止,我還無法爲我的新指令編寫測試,所以我進一步簡化了,直到我的自定義代碼甚至沒有發揮作用。我仍然沒有通過我認爲是微不足道的測試。我究竟做錯了什麼?試圖在噴霧路線上運行一個微不足道的Scalatest
import org.scalatest.FlatSpec
import spray.http.StatusCodes
import spray.routing.{HttpService, Directives, Route}
import spray.testkit.ScalatestRouteTest
trait TrivialDirectivesTextFixture extends Directives {
def trivialRoute: Route =
path("test_route") {
get { requestContext =>
println("get")
complete(StatusCodes.OK, "trivial response")
}
}
}
class TrivialDirectivesSpec extends FlatSpec with TrivialDirectivesTextFixture with ScalatestRouteTest with HttpService {
def actorRefFactory = system
"TrivialDirectives" should "trivially match" in {
Get("/test_route") ~> sealRoute(trivialRoute) ~> check {
println("check")
assertResult(StatusCodes.OK) {
println("status " + status)
status
}
assertResult("trivial response") {
println("response " + response)
responseAs[String]
}
}
}
}
產生的輸出是:
get
check
[info] TrivialDirectivesSpec:
[info] TrivialDirectives
[info] - should trivially match *** FAILED ***
[info] Request was neither completed nor rejected within 1 second (TrivialDirectivesSpec.scala:30)
或者你剛剛刪除'requestContext =>'。 – jrudolph
也可以,@jrudolph。謝謝! – broadmonkey