http4s:实际值和预期值有什么区别?
http4s: What is difference between actual and expected value?
版本:
- http4s: 0.18.1
- 规格 2:4.0.0
我正在使用 http4s 并为路由器编写单元测试,但是关于 headers 断言的文档很少。
执行下面的代码时,可以编译,但是编译失败。
代码:
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
实际值和预期值有什么区别?如果错了,请告诉我如何断言headers。
这几乎可以肯定是一个错误,因为 one of Http4s's own tests does something similar and fails when I run it with Http4sMatchers
with a similar error. I've reported a bug。
版本:
- http4s: 0.18.1
- 规格 2:4.0.0
我正在使用 http4s 并为路由器编写单元测试,但是关于 headers 断言的文档很少。
执行下面的代码时,可以编译,但是编译失败。
代码:
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
实际值和预期值有什么区别?如果错了,请告诉我如何断言headers。
这几乎可以肯定是一个错误,因为 one of Http4s's own tests does something similar and fails when I run it with Http4sMatchers
with a similar error. I've reported a bug。