From 6b02cedd5a0664ec50276ee2577fa591a23d114b Mon Sep 17 00:00:00 2001 From: Graeme Rocher Date: Tue, 12 Nov 2013 14:30:51 +0100 Subject: [PATCH] fix for GRAILS-10720 "Cannot create mock for class" - Horrible, horrible hack, but not choice due to https://code.google.com/p/spock/issues/detail?id=335 --- .../grails/test/spock/GrailsSpecTestType.groovy | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy b/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy index b243a32f37a..e19785ec9a2 100644 --- a/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy +++ b/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy @@ -27,6 +27,8 @@ import org.junit.runner.Request import org.junit.internal.requests.FilterRequest import org.junit.runner.manipulation.Filter import org.junit.runner.Description +import org.objenesis.ObjenesisHelper +import org.objenesis.ObjenesisBase @CompileStatic class GrailsSpecTestType extends GrailsTestTypeSupport { @@ -36,6 +38,20 @@ class GrailsSpecTestType extends GrailsTestTypeSupport { private int featureCount = 0 protected GrailsTestMode mode + static { + try { + final objStdField = ObjenesisHelper.getDeclaredField("OBJENESIS_STD") + objStdField.accessible = true + final objStd = objStdField.get(ObjenesisHelper) + final cacheField = ObjenesisBase.getDeclaredField("cache") + cacheField.accessible = true + cacheField.set(objStd, null) + } catch (Throwable e) { + // ignore, failed to patch + } + + } + GrailsSpecTestType(String name, String relativeSourcePath) { super(name, relativeSourcePath) }