Search code examples
scalaspecs2

Executing Specification with Scope does not call sub tests


Given the following Specification

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)
  }
}

the two examples "buffer should contain a proper config" and "buffer should have fresh config" never get called. What does have to be changed to get this working?


Solution

  • Scopes can only be used on "terminal" examples:

    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
      }
    }