【发布时间】:2016-01-27 17:28:29
【问题描述】:
在 Play framework specs2 测试中,我有这些行...
new WithApplication {
val homeResponse = route(FakeRequest(GET, "/")).get
val resultType = contentType(homeResponse)
resultType.must( beSome.which( _ == "text/html") )
}
^ 这可行,但是当我将“ beSome.which( _ == "text/html") ”拉到一个单独的变量中时...
new WithApplication {
val homeResponse = route(FakeRequest(GET, "/")).get
val resultType = contentType(homeResponse)
val textTypeMatcher = beSome.which( _ == "text/html")
resultType.must( textTypeMatcher )
}
^ 类型不匹配。
预期:Matcher[Option[String]],实际:OptionLikeCheckedMatcher[Option, Nothing, Nothing] ^
这里发生了什么?
【问题讨论】:
-
可能是根据
resultType推断出_的类型。怎么样:val textTypeMatcher = beSome[String].which( _ == "text/html")? -
你不需要
.which(_ == "text/html")部分,beSome("text/html")工作正常。