0

I have a private method in the controller under test that I've exercised and just want to mock in further tests. In grails 2.3.4 the following code worked:

controller.metaClass.method = { a, b -> 'value' }

But in grails 3.3.8 this doesn't seem to have an effect, and it uses the actual controller method. How do I mock this in grails 3.3.8?

1 Answer 1

0

I finally found a bit of info here:

groovy per instance metaClass method override doesnt work as expected in spock test

and the linked bug report:

https://issues.apache.org/jira/browse/GROOVY-7368.

I tried adding types to the params which didn't seem very groovy and didn't make a difference anyway.

Removing 'private' from the method did allow the metaClass mocking to work and the testcase to pass. I'm not real fond of that solution but right now it's all I've got.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.