I have a method that receives a ContactForm
object and a map with recipients. So I wrote the following spec that the correct recipient from the Map is returned, based on the inquiry of the form:
def "Correct recipients for first inquiry"() {
setup:
def form = Mock(ContactForm)
form.getInquiry() >> "Subject 1"
expect:
sut.getRecipients(form, recipientsTestMap) == ["recipient1"]
}
def "Correct recipients for second inquiry"() {
setup:
def form = Mock(ContactForm)
form.getInquiry() >> "Subject 2"
expect:
sut.getRecipients(form, recipientsTestMap) == ["recipient2"]
}
// and so on ...
Is there a data-driven way to do this? Unfortunately, not passing the form but the inquiry string itself is not an option right now, since this would require massive refactoring. I was just curious if it is possible with Spock to do this data-driven although the mock has to be changed before each test.