mercredi 19 septembre 2018

http4s: What is difference between actual and expected value?

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.

Aucun commentaire:

Enregistrer un commentaire