title: Spock No thread-bound request found
body: <p>I have created a simple util class UtilService.groovy and when I tried to run write test case for it.
  class UtilService {</p>
  
  <pre><code>static transactional = true
  
  def messageSource
  
  
  HttpServletRequest getCurrentRequest() {
      GrailsWebRequest webUtils = WebUtils.retrieveGrailsWebRequest()
      def request = webUtils.getCurrentRequest()
      return request
  }
  
  String getMessage(String code, Object[] args = null, String defaultMessage = null) {
      HttpServletRequest request = currentRequest
      Locale locale = request.locale
      if (defaultMessage) {
          return messageSource.getMessage(code, args, defaultMessage, locale)
      } else {
          return messageSource.getMessage(code, args, locale)
      }
  }
  </code></pre>
  
  <p>Test case </p>
  
  <pre><code>@TestMixin(GrailsUnitTestMixin)
  class UtilServiceSpec extends Specification {
  
      void "Test get message"() {
          setup:
              def utilService = new UtilService()
  
          when:
              String data = utilService.getMessage("payCode.label")
  
          then:
              data == "Pay Code"
      }
  }
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? 
  </code></pre>
  
  <p>I have searched and try some links from google but they did not work for me.</p>