在 play2 中使用 'is' 风格的 specs2

use specs2 in 'is' style with play2

class ServiceTest extends PlaySpecification with Mockito {

  override def is =
    s2"""
    This is Service Specification

    The Service  should create element in right way          $init

    """
  val metricId = 1
  val hashid = HashIdGenerator.hashId(metricId)
  def init = 1 mustEqual (1)

}

HashIdGenerator 需要播放应用程序启动,播放文档显示我们需要通过这种方式获取播放应用程序:https://www.playframework.com/documentation/2.1.0/ScalaTest

  "Computer model" should {

  "be retrieved by id" in new WithApplication {
    // your test code
  }
  "be retrieved by email" in new WithApplication {
    // your test code
  }
}

但我不喜欢这种 'should in ' 风格,所以我怎样才能获得播放应用程序并同时继续使用 'is' 风格。

使用 WithApplication 包装依赖播放应用程序的代码:

  val Id = 1
  val app = new WithApplication {
    val hashId = HashIdGenerator.hashId(Id)
  }
  val hashId = app.hashId