gpt4 book ai didi

scala - http4s:实际值和预期值有什么区别?

转载 作者:行者123 更新时间:2023-11-28 20:10:35 26 4
gpt4 key购买 nike

版本:

  • http4s: 0.18.1
  • 规范2:4.0.0

我正在使用 http4s 并为路由器编写单元测试,但是关于 header 断言的文档很少。

下面代码执行时,可以编译,但是编译失败。

代码:

import cats.effect.IO
import org.http4s._
import org.http4s.dsl.io._
import org.http4s.headers._
import org.http4s.testing.Http4sMatchers
import org.specs2.mutable.Specification

class RedirectSpec extends Specification with Http4sMatchers {
"testing" >> {
val response: IO[Response[IO]] = Found(Location(Uri.unsafeFromString("")))
response must returnStatus(Found)
response must returnValue(
haveHeaders(
Headers(
`Content-Length`.zero,
Location(Uri.unsafeFromString(""))
)
)
)
}
}

输出:

$  sbt "testOnly RedirectSpec"
...
[info] RedirectSpec
[error] x testing
[error] the headers 'Headers(Content-Length: 0, Location: )' is not the same as Headers(Content-Length: 0, Location: ) (RedirectSpec.scala:13)
[info] Total for specification RedirectSpec
[info] Finished in 655 ms
[info] 1 example, 1 failure, 0 error
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error] RedirectSpec
[error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful

实际值和预期值有什么区别?如果错了,请告诉我如何对 header 进行断言。

最佳答案

这几乎可以肯定是一个错误,因为 one of Http4s's own tests做了类似的事情,当我用 Http4sMatchers 运行它时失败并出现类似的错误。我有 reported a bug .

关于scala - http4s:实际值和预期值有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52416411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com