Multiple when/then with where for each other

grails, spock, testing

Solution

You will not be able to use `where` per interaction, it would complain about the usage. You would end up with a single `where` for multiple interactions. Follow this as a sample:

def test() {
  given:   
  def c
  def d

  when:
  c = a + b

  then:
  c == result

  when:
  d = e - f

  then:
  d == res

  where:
  a | b |result | e |f |res
  1 | 2 | 3     | 7 |5 |2
}

Problem

I'm trying to write functional test with Spock and Geb. I want to use in one test method multiple blocks of when/then with where for each block. Is it possible? Or I should use one where for all the when/then?

Original source