Specs2 - 忽略具有一组结果的 Future 的匹配器中的属性
Specs2 - Ignoring properties in a matcher with Future of a set of results
我有以下这个匹配器:
def haveBodyWith[T: TypeTag: Unmarshaller](content: T)(implicit await: Duration): Matcher[Future[HttpResponse]] = {
===(content) ^^ { (f: Future[HttpResponse]) => { Await.result(f, await).entity.as[T].right.get } }
}
我从 HttpResponse 中提取结果,然后将其与预期内容进行比较。到目前为止,这个匹配器工作得很好。现在,我有一个特定的用例,其中响应的内容是 case classes 的序列,我想忽略 case class 的一个属性。我无法完成这项工作:
def haveBodyWith(content: Foo): Matcher[HttpResponse] = {
===(content) ^^ { (_: HttpResponse).entity.as[Foo].right.get.copy(name = "") }
}
case class Foo(id: Int, name: String)
如果我只有内容而没有未来可以比较,我会这样做(可能类似于 Seq of case classes),但是未来让它变得有点困难.
你怎么看?
谢谢!
讨论发生在Google groups,最后的解决方案是:
def haveBodyWith1(content: Foo): Matcher[Future[HttpResponse]] = {
===(normalize(content)) ^^ { (response: HttpResponse) =>
normalize(response.foo) }
}.await
def normalize(foo: Foo) = foo.copy(name = "")
我有以下这个匹配器:
def haveBodyWith[T: TypeTag: Unmarshaller](content: T)(implicit await: Duration): Matcher[Future[HttpResponse]] = {
===(content) ^^ { (f: Future[HttpResponse]) => { Await.result(f, await).entity.as[T].right.get } }
}
我从 HttpResponse 中提取结果,然后将其与预期内容进行比较。到目前为止,这个匹配器工作得很好。现在,我有一个特定的用例,其中响应的内容是 case classes 的序列,我想忽略 case class 的一个属性。我无法完成这项工作:
def haveBodyWith(content: Foo): Matcher[HttpResponse] = {
===(content) ^^ { (_: HttpResponse).entity.as[Foo].right.get.copy(name = "") }
}
case class Foo(id: Int, name: String)
如果我只有内容而没有未来可以比较,我会这样做(可能类似于 Seq of case classes),但是未来让它变得有点困难. 你怎么看?
谢谢!
讨论发生在Google groups,最后的解决方案是:
def haveBodyWith1(content: Foo): Matcher[Future[HttpResponse]] = {
===(normalize(content)) ^^ { (response: HttpResponse) =>
normalize(response.foo) }
}.await
def normalize(foo: Foo) = foo.copy(name = "")