使用Scope执行规范不会调用子测试

时间:2015-07-16 12:35:31

标签: scala specs2

给出以下规范

class Config2Spec extends org.specs2.mutable.Specification {
  "reading different versions of config should work" in new aScope  {
    "buffer should contain a proper config" in {
      buffer(0).content should have size 1
    }
   "buffer should have fresh config" in {
      buffer should have size 2
      buffer(1).content should have size 2
    }
 }

 trait aScope extends Scope {
   val buffer : mutable.Buffer[Config] = mutable.Buffer()
   val cfg1 = "l1"

   val cfg2 = "l1\nl2"

   val file = "testCfg"
   val path = Paths.get(System.getProperty("user.home"), "test")
   Files.createDirectories(path)
   val of = ObservableFile(path, file)
   Files.write(of.asPath, cfg1.getBytes("UTF-8"))
   buffer += ConfigReader.read(file, {cfg => buffer += cfg})
   Files.write(of.asPath, cfg2.getBytes("UTF-8"))
   Thread.sleep(1000)
  }
}

这两个例子"缓冲区应该包含一个正确的配置"和"缓冲区应该有新配置"永远不会被打电话为了让这个工作有什么必要改变?

1 个答案:

答案 0 :(得分:1)

范围只能用于“终端”示例:

class Config2Spec extends org.specs2.mutable.Specification {
  "reading different versions of config should work" in {
    "buffer should contain a proper config" in new aScope {
      i === 0
      i += 1
    }
    "buffer should have fresh config" in new aScope {
      i === 0
      i += 1
   }
 }

  trait aScope extends Scope {
    var i = 0
  }
}
相关问题