Created
February 11, 2013 21:45
-
-
Save andrewconner/4757896 to your computer and use it in GitHub Desktop.
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
class TranslateSpec extends Specification { | |
"Translate" should { | |
// The normal Play! way | |
"accept a name, and return a proper greeting" in { | |
running(FakeApplication()) { | |
val translated = route(FakeRequest(GET, "/greet/Barney")).get | |
status(translated) must equalTo(OK) | |
contentType(translated) must beSome.which(_ == "text/html") | |
contentAsString(translated) must contain ("Barney") | |
} | |
} | |
// Providing a fake Global, to explitly mock out the injector | |
object FakeTranslatorGlobal extends play.api.GlobalSettings { | |
override def getControllerInstance[A](clazz: Class[A]) = { | |
new Translate(new FakeTranslator).asInstanceOf[A] | |
} | |
} | |
"accept a name, and return a proper greeting (explicitly mocking module)" in { | |
running(FakeApplication(withGlobal = Some(FakeTranslatorGlobal))) { | |
val home = route(FakeRequest(GET, "/greet/Barney")).get | |
contentAsString(home) must contain ("Hello Barney") | |
} | |
} | |
// Calling the controller directly, without creating a new FakeApplication | |
// (This is the fastest) | |
"accept a name, and return a proper greeting (controller directly, no FakeApplication!)" in { | |
val controller = new Translate(new FakeTranslator) | |
val result = controller.greet(name = "Barney")(FakeRequest()) | |
contentAsString(result) must contain ("Hello Barney") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment