http4s: What is difference between actual and expected value?

274 Views Asked by At

versions:

  • http4s: 0.18.1
  • specs2: 4.0.0

I'm using http4s and writing unit test for routers, but there are little documents about headers assertion.

When code below is executed, it can be compiled, but fails.

code:

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(""))
        )
      )
    )
  }
}

output:

$  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

What is difference between actual and expected value? If it's wrong, please tell me how to make assertion about headers.

1

There are 1 best solutions below

0
On BEST ANSWER

This is almost certainly a bug, since 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.