2

Is it possible to define a behavior of a mock in the setup() method and then override it in some test methods? Something like this:

SomeMockableObject smo = Mock()

def setup() {
  smo.returnSomething() >> "foo"
}

def "test method that expects smo to return 'foo'"() {
  // some test code
}

def "test method that expects smo to return 'bar'"() {
  given:
  smo.returnSomething() >> "bar"

  // some test code
}

I have tried this, but smo.returnSomething() always returns "foo". Am I doing something wrong or is it just not possible to do this?

woezelmann
  • 1,355
  • 2
  • 19
  • 39
  • 4
    sorry for bothering you, just found my anwser http://stackoverflow.com/questions/22215929/spock-can-an-interaction-defined-in-setup-be-replaced-in-a-test-case?rq=1 – woezelmann Feb 12 '15 at 08:37

0 Answers0