-
-
Save gregopet/7aedd77f4cf638fa31a9 to your computer and use it in GitHub Desktop.
A way of testing closures in Grails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def action() { | |
mailService.sendMail emailParameters(params.mailTo, params.subject, params.body, attachments) | |
} | |
protected Closure emailParameters(List<String> mailTo, String mailSubject, String mailBody, List attachments) { | |
return { | |
multipart true | |
to mailTo | |
subject mailSubject | |
body mailBody | |
attachments.each { | |
attachBytes (it.filename, it.mime, it.bytes) | |
} | |
} as Closure | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ".emailParameters creates a configuration closure with the right properties set"() { | |
given: | |
def closure = controller.emailParameters(emailTo, emailSubject, emailBody, attachments) | |
def closureDelegate = Mock(Closure) | |
closure.delegate = closureDelegate | |
when: | |
closure() | |
then: | |
1*closureDelegate.invokeMethod('multipart', [true]) | |
where: | |
emailBody = "body" | |
emailSubject = "subject" | |
emailTo = ["somebody@example.org"] | |
attachments = [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment