For the testing futures with specs2, if one is using play2.4 and also specs3.5, in order to be able to use the await method when testing futures, one should import the specs2 execution environment and add that to each block implicitly:
import org.specs2.matcher.Matchers
import org.specs2.mutable.Specification
import org.specs2.time.NoTimeConversions
import scala.concurrent.duration._
import org.specs2.concurrent.ExecutionEnv
class AuthenticationServiceSpec extends Specification with Matchers with NoTimeConversions {
"The AuthenticationService" should {
val service: AuthenticationService = new DummyAuthenticationService
"correctly authenticate Bob Marley" in { implicit ee: ExecutionEnv =>
service.authenticateUser("bob@marley.org", "secret") must beEqualTo (AuthenticationSuccessful).await(1, 200.millis)
}
"not authenticate Ziggy Marley" in { implicit ee: ExecutionEnv =>
service.authenticateUser("ziggy@marley.org", "secret") must beEqualTo (AuthenticationUnsuccessful).await(1, 500.millis)
}
"fail if it takes too long" in { implicit ee: ExecutionEnv =>
service.authenticateUser("jimmy@hendrix.com", "secret") must throwA[RuntimeException].await(1, 700.millis)
}
}
}
For the testing futures with specs2, if one is using play2.4 and also specs3.5, in order to be able to use the await method when testing futures, one should import the specs2 execution environment and add that to each block implicitly: