Skip to content

Instantly share code, notes, and snippets.

@sergiomichels
Created October 25, 2013 19:37
Show Gist options
  • Save sergiomichels/7160616 to your computer and use it in GitHub Desktop.
Save sergiomichels/7160616 to your computer and use it in GitHub Desktop.
Set the Locale of your integration test
import grails.plugin.spock.IntegrationSpec
import org.springframework.web.context.request.RequestContextHolder
class MyTestSpec extends IntegrationSpec {
/* Normally in your code you will use something like RequestContextUtils.getLocale(request) to get's the Locale to
* be used. Here we set the locale that will be returned by RCU to our tests.
*/
def setup() {
//get's the instance of the mock
def request = RequestContextHolder.currentRequestAttributes().request
//and then set your locale
request.addPreferredLocale(new Locale("pt","BR"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment