Source:
<code>public Object intercept(Object target, Method method, Object[] arguments, IResponseGenerator realMethodInvoker) { IMockObject mockObject = new MockObject(mockConfiguration.getName(), mockConfiguration.getExactType(), target, mockConfiguration.isVerified(), false, mockConfiguration.getDefaultResponse(), specification, this); if (method.getDeclaringClass() == ISpockMockObject.class) { return mockObject; } Object[] normalizedArgs = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments); if (target instanceof GroovyObject) { if (isMethod(method, "getMetaClass")) { return mockMetaClass; } if (isMethod(method, "setProperty", String.class, Object.class)) { Throwable throwable = new Throwable(); StackTraceElement mockCaller = throwable.getStackTrace()[3]; if ("org.codehaus.groovy.runtime.ScriptBytecodeAdapter".equals(mockCaller.getClassName())) { String methodName = GroovyRuntimeUtil.propertyToMethodName("set", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName, GroovyRuntimeUtil.asArgumentArray(normalizedArgs[1])); } } if (isMethod(method, "getProperty", String.class)) { Throwable throwable = new Throwable(); StackTraceElement mockCaller = throwable.getStackTrace()[3]; <START> if (!("groovy.lang.GroovyObject$getProperty".equals(mockCaller.getClassName()) && "call".equals(mockCaller.getMethodName()))) { <END> String methodName = GroovyRuntimeUtil.propertyToMethodName("get", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName); } } } IMockMethod mockMethod = new StaticMockMethod(method, mockConfiguration.getExactType()); IMockInvocation invocation = new MockInvocation(mockObject, mockMethod, Arrays.asList(normalizedArgs), realMethodInvoker); IMockController mockController = specification == null ? getFallbackMockController() : specification.getSpecificationContext().getMockController(); return mockController.handle(invocation); }</code><technical_language>Please include a //HACK: scanning stacktrace, extend if a isGroovy3() check</technical_language>

Target:
public Object intercept(Object target, Method method, Object[] arguments, IResponseGenerator realMethodInvoker) { IMockObject mockObject = new MockObject(mockConfiguration.getName(), mockConfiguration.getExactType(), target, mockConfiguration.isVerified(), false, mockConfiguration.getDefaultResponse(), specification, this); if (method.getDeclaringClass() == ISpockMockObject.class) { return mockObject; } Object[] normalizedArgs = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments); if (target instanceof GroovyObject) { if (isMethod(method, "getMetaClass")) { return mockMetaClass; } if (isMethod(method, "setProperty", String.class, Object.class)) { Throwable throwable = new Throwable(); StackTraceElement mockCaller = throwable.getStackTrace()[3]; if ("org.codehaus.groovy.runtime.ScriptBytecodeAdapter".equals(mockCaller.getClassName())) { String methodName = GroovyRuntimeUtil.propertyToMethodName("set", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName, GroovyRuntimeUtil.asArgumentArray(normalizedArgs[1])); } } if (GroovyRuntimeUtil.isGroovy3orNewer()) { if (isMethod(method, "getProperty", String.class)) { Throwable throwable = new Throwable(); StackTraceElement mockCaller = throwable.getStackTrace()[3]; if (!("groovy.lang.GroovyObject$getProperty".equals(mockCaller.getClassName()) && "call".equals(mockCaller.getMethodName()))) { String methodName = GroovyRuntimeUtil.propertyToMethodName("get", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName); } } } } IMockMethod mockMethod = new StaticMockMethod(method, mockConfiguration.getExactType()); IMockInvocation invocation = new MockInvocation(mockObject, mockMethod, Arrays.asList(normalizedArgs), realMethodInvoker); IMockController mockController = specification == null ? getFallbackMockController() : specification.getSpecificationContext().getMockController(); return mockController.handle(invocation); }