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

时间:2018-09-20 01:50:10

标签: scala testing http4s

版本:

  • http4s:0.18.1
  • specs2: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

实际值和期望值有什么区别?如果不对,请告诉我如何对标头进行断言。

1 个答案:

答案 0 :(得分:1)

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