I'm trying to validate that this groovy closure in a class called CUTService has the correct values:
mailService.sendMail {
to 'hey@example.com'
from 'hey@example.com'
subject 'Stuff'
body 'More stuff'
}
I've looked at https://github.com/craigatk/spock-mock-cheatsheet/raw/master/spock-mock-cheatsheet.pdf, but his syntax produces an error:
1 * mailService.sendMail({ Closure c -> c.to == 'hey@example.com'})
groovy.lang.MissingPropertyException: No such property: to for class: com...CUTService
I've looked at Is there any way to do mock argument capturing in Spock and tried this:
1 * mailService.sendMail({closure -> captured = closure })
assertEquals 'hey@example.com', captured.to
which produces:
groovy.lang.MissingPropertyException: No such property: to for class: com...CUTService
I also tried this:
1 * mailService.sendMail({captured instanceof Closure })
assertEquals 'hey@example.com', captured.to
which produces:
Too few invocations for:
1 * mailService.sendMail({captured instanceof Closure }) (0 invocations)
...
Unmatched invocations (ordered by similarity):
1 * mailService.sendMail(com...CUTService$_theMethod_closure5@21a4c83b)
What do I need to do to get this working?