我在Scala/Play 2.0和Specs中遇到了一個簡單的問題。在Scala中使用與Specs2和Play匹配的模式
這是我的測試
"Server" should {
"return a valid item with appropriate content type or a 404" in {
val Some(result) = routeAndCall(FakeRequest(GET, "/item/1"))
status(result) match {
case 200 => contentType(result) must beSome("application/json")
case 404 => true
case _ => throw new Exception("The Item server did not return either a 200 application/json or a 404")
}
//false --> It only compiles if I add this line!
}
}
}
這並不編譯,因爲以下內容:
No implicit view available from Any => org.specs2.execute.Result.
[error] "return a valid item with appropriate content type or a 404" in {
[error] ^
[error] one error found
因此,進出口思維狀態(結果)匹配評估對任何因此錯誤。我應該如何指定它的結果類型是Result,因爲我有一個帶有錯誤返回值的默認情況?
可以添加'不得(throwA [MyException])'在末端。我會堅持一些自定義的異常,而不是一般的異常。 –
我在最後添加時遇到了麻煩,我嘗試過在匹配後添加它ie - > status(result)match {...} must(throwA [Exception]),現在我得到:';'預期但找到標識符。 [錯誤] \t \t \t \t}不能(throwA [例外]) – dgrandes