Search code examples
scalaspecs2

Is it necessary to use `class` instead of `object` when using `isolated` for specs2 tests?


For specs2 tests, we can use object or class to contain tests:

object MyTests extends Specification
class MyTests extends Specification

But if I want to use isolated, must I use class?

class MyTests extends Specification {
  isolated
}

I ask this because I found, when I use object, the tests sometimes reports an error:

NoSuchElementException: : head of empty list  (file:1)

But it disappeared when I change to class


Solution

  • This is indeed a bug with the version of specs2 which you are using. This part has been re-implemented in specs2 3.x and is working fine.