jeudi 15 décembre 2016

My Play Application's Constructor takes an argument, how do I give a mocked argument at Spec Test?

If my play application has something like this:

class Foo() extends Bar {} 

class Application @Inject (f: Foo) extends Controller {
  def index = Action { OK("Hi, Foo App") }
}

How do I change my spec test to accept MockedFoo class?

@RunWith(classOf[JUnitRunner])

class MockedFoo() extends Bar {}

class ApplicationTest(implicit ee: ExecutionEnv) extends Specification  {

  "Sending a GET request to index " should {

    "Respond with OK " in new WithApplication { //######## Inject MockedFoo
      val response = route(app, FakeRequest(GET, "/")).get
      status(response) mustEqual OK
    }
  }
}

Thanks for the help:

Aucun commentaire:

Enregistrer un commentaire