Skip to content

Instantly share code, notes, and snippets.

@caoilte
Last active May 18, 2017 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caoilte/e8f5624ecf30f6f1d615cfe5636329fa to your computer and use it in GitHub Desktop.
Save caoilte/e8f5624ecf30f6f1d615cfe5636329fa to your computer and use it in GitHub Desktop.
unit testing HTTP4s encoders
package httpServices
import io.circe.{Encoder, Printer}
import org.http4s.circe.CirceInstances
import org.scalatest.{FlatSpec, Matchers}
import org.http4s.dsl._
class GistTest extends FlatSpec with Matchers {
case class TestObject(someValue: Int, someOptionalValue:Option[Int])
object TestObject {
import io.circe.generic.semiauto._
implicit val testObjectEncoder: Encoder[TestObject] = deriveEncoder[TestObject]
}
object Encoders extends CirceInstances {
override protected def defaultPrinter: Printer = Printer.noSpaces.copy(dropNullKeys = true)
implicit val schedulesEncoder = jsonEncoderOf[TestObject]
}
it should "Test the Encoders Object concisely!" in {
import Encoders._
// It would be nice to be able to test the Encoders._ object without creating an `Ok` response
Ok(TestObject(5, None)).as[String].unsafePerformSync shouldEqual
"""{"someValue":5}"""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment