僕は Expecty を試してみたかったので、eed3si9n/expecty にフォークして、sbt ビルドを追加して、コードが Scala 2.10、2.11、2.12、2.13.0-M4 で動作するようにパッチを当てて、上流にプルリクを還元した後でパッケージ名を変更して、Maven Central に公開した:
libraryDependencies += "com.eed3si9n.expecty" %% "expecty" % "0.11.0" % Test
Scala.JS か Scala Native の場合は:
libraryDependencies += "com.eed3si9n.expecty" %%% "expecty" % "0.11.0" % Test
以下のように使うことができる:
scala> import com.eed3si9n.expecty.Expecty.assert
import com.eed3si9n.expecty.Expecty.assert
scala> assert(a * b == 7)
java.lang.AssertionError:
assert(a * b == 7)
| | | |
1 3 3 false
at com.eed3si9n.expecty.Expecty$ExpectyListener.expressionRecorded(Expecty.scala:25)
at com.eed3si9n.expecty.RecorderRuntime.recordExpression(RecorderRuntime.scala:34)
... 38 elide
上のように、ナイスなエラーメッセージが自動的に得られる。