One possible solution:
class Application(emailChecker: EmailChecker) extends Controller {
def login = Action {implicit request =>
val email = ...
if(emailChecker.checkEmail(email)) {
Ok("Email is checked and is fine")
} else {
Ok("Email is wrong")
}
}
}
object Application extends Application(EmailChecker)
And the test will be:
import org.specs2.Specification
import org.specs2.mock.Mockito
class ApplicationUnitSpec extends Specification with Mockito { def is =
"Test Application" ! {
val emailChecker = mock[EmailChecker]
val response = new Application(emailChecker).login(FakeRequest)
there was one(emailChecker).checkEmail("blah@example.com")
}
}
, Real Test implicits, , , , EmailChecker, , . emailChecker . .