Last active
September 20, 2019 19:14
-
-
Save grimrose/ded2a0d3b348ec3718c5bfc0de9f2f6f to your computer and use it in GitHub Desktop.
AirSpec(19.9.7) for Scala Future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ninja.grimrose.sandbox | |
import wvlet.airframe.SourceCode | |
import wvlet.airspec.AirSpec | |
import wvlet.airspec.spi.AssertionFailure | |
import scala.concurrent.{ExecutionContext, Future} | |
import scala.util.{Failure, Success} | |
trait ScalaFutureSupport { this: AirSpec => | |
import scala.concurrent.duration._ | |
import scala.language.implicitConversions | |
protected def timeout: Duration = 1.minutes | |
implicit def executionContext: ExecutionContext | |
implicit class RichFuture[T](scalaFuture: Future[T]) { | |
def assertAsync(cond: T => Boolean)(implicit code: SourceCode): Unit = { | |
scalaFuture.value match { | |
case Some(s: Success[T]) => assert(cond(s.value)) | |
case Some(f: Failure[T]) => throw f.exception | |
case None => throw AssertionFailure("future value is None", code) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scala.js 0.6.29