Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 5 - Testing futures #2

Closed
lucianenache opened this issue Jul 22, 2015 · 1 comment
Closed

chapter 5 - Testing futures #2

lucianenache opened this issue Jul 22, 2015 · 1 comment

Comments

@lucianenache
Copy link

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)
    }
  }
}
@manuelbernhardt
Copy link
Owner

@lucianenache thanks, I fixed that when upgrading the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants