grails - Spock throws MissingMethodException on dynamic method that is not presented in interface -
i have groovy.lang.groovyobject interface extended. implementor class not have public constructor , contains dynamic method not presented in inteface.
i'm trying this:
def bean = stub(groovyobject) bean.getresults() >> ['result1', 'results2']
while invoking:
bean.getresults()
it throw groovy.lang.missingmethodexception. in fact not carry interface contract, merely need make sure stubed object returns expected list.
also cannot stub implementor class, throw cannotcreatemockexception.
it seems have found solution myself.
instead of stub groovystub has used. allow no verification against methods of stubed class. groovyobject interface didn't work, had use groovyobjectsupport abstract class:
def bean = groovystub(groovyobjectsupport) bean.getresults() >> ['result1', 'results2'] assert bean.getresults() == ['result1', 'results2']
Comments
Post a Comment