I\'d like to test a method that returns a Future
. My attempts were as follows:
import org.specs2.mutable.Specification
import scala.concurrent.Exec
onComplete
returns Unit
, so that block of code returns immediately and the test ends before being able to do anything. In order to properly test the result of a Future
, you need to block until it completes. You can do so using Await
, and setting a maximum Duration
to wait.
import scala.concurrent._
import scala.concurrent.duration._
Await.result(testImage, Duration("10 seconds")) must not have length(0)