我正在使用Play!框架并尝试在Specs2测试中使用JSON响应消息但没有成功.
我想要做的是在JsValue中断言key->值对,如下例所示...但我无法让匹配器正确传递.
import org.specs2.mutable._
import play.api.libs.json.{Json, JsValue}
class JsonSpec extends Specification {
"Json Matcher" should {
"Correctly match Name->Value pairs" in {
val resultJson:JsValue = Json.parse("""{"name":"Yardies"}""")
resultJson must /("name" -> "Yardies")
}
"Correctly match Name->Value pairs with numbers as doubles" in {
val resultJson:JsValue = Json.parse("""{"id":1}""")
resultJson must /("id" -> 1.0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
{name : Yardies} doesn't contain '(name,Yardies)'
Run Code Online (Sandbox Code Playgroud)
和
{id : 1.0} doesn't contain '(id,1.0)'
Run Code Online (Sandbox Code Playgroud)
不是很有帮助,我想这是我想念的简单事件(Scala和Play都是新手)
史蒂夫