小编sMo*_*ely的帖子

Playframework Scala Specs2 JSON Matchers

我正在使用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都是新手)

史蒂夫

json scala specs2 playframework-2.0

4
推荐指数
1
解决办法
2337
查看次数

标签 统计

json ×1

playframework-2.0 ×1

scala ×1

specs2 ×1