There are many ways to define expectations in
true, false)success, failure)1 must ===(1))All of these types implement the
org.specs2.execute.AsResult typeclass, meaning that they
can be transformed into a Result:
trait AsResult[T]:
def asResult(t: =>T): Result
This gives some flexibility in integrating any kind of custom
definition of a “result” into
// A new type of results for cluster execution
trait ClusterExecution:
def succeeded: Boolean
def errorMessage: String
object ClusterExecution:
given AsResult[ClusterExecution] =
new AsResult[ClusterExecution]:
def asResult(t: =>ClusterExecution): Result =
try {
val result = t
if (result.succeeded) Success()
else Failure(t.errorMessage)
} catch { case e: Throwable => Error(e) }
You can also embed custom data in a special kind of
Result, with the
org.specs2.result.DecoratedResult class:
case class DecoratedResult[+T](decorator: T, result: Result) extends Result(result.message, result.expected)
A DecoratedResult[T] decorates an ordinary result with
an additional value of type T. If you want to take
advantage of this custom value in your reports you will need to build a
custom org.specs2.reporter.Printer, probably extending an
existing one.
AsResult instance as
"pending
until fixed"