【问题标题】:use specs2 in 'is' style with play2在 play2 中使用“is”风格的 specs2
【发布时间】:2016-04-05 09:29:28
【问题描述】:
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' 风格,所以我怎样才能获得一个 play 应用程序并同时继续使用 'is' 风格。

【问题讨论】:

    标签: playframework playframework-2.0 specs2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      • 2013-09-08
      • 2020-09-15
      • 2015-07-03
      相关资源
      最近更新 更多