http4s:实际价值和期望值有什么区别?



versions:

  • http4s: 0.18.1
  • 规格2: 4.0.0

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

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

法典:

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

实际价值和预期价值有什么区别?如果错了,请告诉我如何对标题做出断言。

这几乎可以肯定是一个错误,因为 Http4s 自己的测试之一也做了类似的事情,当我使用带有类似错误的Http4sMatchers运行时失败了。我报告了一个错误。

最新更新