I am currently doing this noblest programming by writing tests for Json encoding / decoding. I use Argonaut.io for Json and Scalatest for my testing platform. With a scatbet, using === during verification validation provides additional information if a failure occurs, while using == just gives it org.scalatest.exceptions.TestFailedException was thrown. . However, the scala compiler is not happy. Here is the code:
val default = new Broadcast("default", "default", "default") test("Should parse out network when present") { val hcursor = testHCursor(jsonPath + "complete-broadcast.json") val actualNetwork = Parser.BroadcastDecodeJson(hcursor) .getOr(default) .network assert(actualNetwork === "ESPNU") }
It spews this out:
[info] Compiling 1 Scala source to /home/vagrant/waltercamp/waltercamp-dataservice/target/scala-2.10/test-classes... [error] /home/vagrant/waltercamp/waltercamp-dataservice/src/test/scala/io/ptx/waltercamp/schedules/BroadcastParserSuite.scala:16: type mismatch; [error] found : actualNetwork.type (with underlying type String) [error] required: ?{def ===(x$1: ? >: String("ESPNU")): ?} [error] Note that implicit conversions are not applicable because they are ambiguous: [error] both method ToEqualOps in trait ToEqualOps of type [F](v: F)(implicit F0: scalaz.Equal[F])scalaz.syntax.EqualOps[F] [error] and method convertToEqualizer in trait Assertions of type (left: Any)BroadcastParserSuite.this.Equalizer [error] are possible conversion functions from actualNetwork.type to ?{def ===(x$1: ? >: String("ESPNU")): ?} [error] assert(actualNetwork === "ESPNU") [error] ^ [error] one error found [error] (test:compile) Compilation failed
However, using == provides a clean compilation and transfer. Is there a way to give the compiler a hint about which transform or transform order to use?
source share