0
votes

I have some specs2 tests with Scope:

"hello" should {
   "return world" in new Subject {
       hello.get === "world"
   }
}
trait Subject extends org.specs2.specification.Scope {
   val hello = new Hello
}

Now I want to convert it into acceptance style:

def is = s2"""
   hello.get should return 'world' $e1
"""
def e1 = new Subject {
    hello.get === "world"
}
trait Subject extends org.specs2.specification.Scope {
   val hello = new Hello
}

It seems working and the test is passed, but soon I found it's never failed no matter how I modify it:

hello.get === "invalid-world" // still passing

How to use Scope correctly in acceptance style?

1

1 Answers

1
votes

Just found an issue for this problem: https://github.com/etorreborre/specs2/issues/180

The answer quoted from there:

This is to be expected. Scopes are traits which are only intended to be used with mutable specifications. You have 2 ways around this:

use a case class or case object

s2"""
 will fail      ${t.fail}
"""
case object t {
  val foo = false
  def fail = foo must beTrue
}

mix-in the ThrownExpectations trait to the Specification so that failed expectations will "bubble-up" outside of the Scope trait