You could set up a callback on the mock:

  val foo = mock[Foo] answers (derp => {
    derp match {
      case "x" => 1
      case "y" => 2
      case _ => throw mock[FooException]

There are some more details in the specs2 documentation.


You need to change the order of your stubbing around. Stub the generalized behavior first (anyString) and then add more specific behaviors after that. So do this:

val foo = mock[Foo] throws mock[FooException]"x") returns 1"y") returns 2

Related Query

More Query from same tag