Last Updated: February 25, 2016
· tuler

Mocking a no-arg method in Grails

Lost hours today around a problem with some unit tests. I found out that in order to mock a method with no args you should do:

control.demand.someMethod { -> true }

instead of

control.demand.someMethod { true }

because the second one is actually a closure with a single arg called * it *. The error grails gives me is:

junit.framework.AssertionFailedError: No call to 'someMethod' expected at this point.

Thanks to http://stackoverflow.com/questions/2922947/grails-mockfor-closure-wierdness