มีข้อกำหนดสองประการที่นี่ อย่างแรกไม่ผ่านเพราะ eventually
ใน check
จะไม่ทำให้เกิดการวิ่งซ้ำทั้งเส้นทาง แต่นี่คือวิธีที่ฉันต้องการติดตาม ข้อมูลจำเพาะที่สองเป็นทางออกที่ดีที่สุดที่ฉันพบ (และพิสูจน์ว่ามันเป็นไปได้ ;) ) แต่มีบางส่วนสำเร็จรูปเช่นฟังก์ชั่นเพิ่มเติมซึ่งในชีวิตจริงจะต้องส่งคืนมากกว่าสิ่งอันดับมากกว่าสิ่งเดียวและไม่สอดคล้องกับการออกแบบไวยากรณ์การทดสอบสเปรย์ เพื่อทดสอบเส้นทาง
คำถามก็คือ จะใช้ eventually
กับการทดสอบแบบสเปรย์อย่างไรให้ใกล้เคียงกับไวยากรณ์จากข้อมูลจำเพาะแรกมากที่สุด
import org.specs2.mutable.Specification
import spray.routing.Directives
import spray.http._
import MediaTypes._
import HttpCharsets._
import spray.testkit.Specs2RouteTest
class EventuallyAndRouts extends Specification with Directives with Specs2RouteTest {
var i = 0
def incAndGet = {
i = i + 1
println(s"This is i = $i")
s"$i"
}
"The testing infrastructure should support an eventually matcher" >> {
"but it is not working inside a check as I need :( (and this will fail)" in {
i = 0
Get() ~> complete(incAndGet) ~> check {
body must eventually(7, 20 millis)(be_===(HttpEntity(ContentType(`text/plain`, `UTF-8`), "5")))
}
}
"so I got workaround :/ (and this is passing)" in {
i = 0
def requestResult = Get() ~> complete(incAndGet) ~> check {
body
}
requestResult must eventually(7, 20 millis)(be_===(HttpEntity(ContentType(`text/plain`, `UTF-8`), "5")))
}
}
}