Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import grails.plugin.spock.*
  2. import org.springframework.context.*
  3. import org.springframework.context.support.*
  4. import spock.lang.*
  5.  
  6. class GreetingControllerSpec extends ControllerSpec {
  7.  
  8. @Shared def messageSource = new StaticMessageSource()
  9. @Shared def pirateEnglish = new Locale("en", "BV")
  10.  
  11. def setupSpec() {
  12. messageSource.useCodeAsDefaultMessage = true
  13. messageSource.addMessage "greeting.message", pirateEnglish, "Ahoy there {0}!"
  14. }
  15.  
  16. def setup() {
  17. mockMessageTag(controller, messageSource)
  18. }
  19.  
  20. @Unroll
  21. def "greeting is rendered by index action"() {
  22. given:
  23. if (name) controller.params.name = name
  24. if (locale) controller.request.addPreferredLocale(locale)
  25.  
  26. expect:
  27. controller.index() == [message: message]
  28.  
  29. where:
  30. name | locale | message
  31. null | null | "greeting.message"
  32. "Rob" | null | "greeting.message"
  33. "Rob" | pirateEnglish | "Ahoy there Rob!"
  34. }
  35.  
  36. // in reality this would be static imported from a helper class
  37. static void mockMessageTag(artefact, MessageSource messageSource) {
  38. artefact.metaClass.message = { attrs ->
  39. messageSource.getMessage(attrs.code, attrs.args as Object[], delegate.request.locale)
  40. }
  41. }
  42. }
Add Comment
Please, Sign In to add comment