When you mix-in the Mockito
trait to another trait you can create expectations like there was one(interface).doSomething
. If such an expression fails it only returns a Result
, it doesn't throw an Exception
. It then gets lost in a Scope
because it is just a "pure" value inside the body of a trait.
However if you mix-in the Mockito
trait to a mutable.Specification
then an exception will be thrown on a failure. This is because the mutable.Specification
class specifies that there should be ThrownExpectations
by mixing in that trait.
So if you want to create a trait extending both Scope
you can either:
create the trait from inside the specification and not have it extend Mockito:
class MySpec extends mutable.Specification with Mockito { trait TestEnvironment extends Scope { val interface = mock[SomeInterface] val test = new ClassBeingTested(interface) } ... }
create trait and specification as you do, but mix-in
org.specs2.execute.ThrownExpectations
trait TestEnvironment extends Scope with Mockito with ThrownExpectations { val interface = mock[SomeInterface] val test = new ClassBeingTested(interface) } class MySpec extends mutable.Specification with Mockito { ... }