Grails mock to close wierdness

Right

so when I customize my layout using the plugin mockFor method, I expect the method to return null. If i do

myControl.demand.theMethod {return null} 

in the debugger, the value I set for the result of calling theMethod is some closure in the debugger.

If i do

 myControl.demand.theMethod {->return null} 

the value is null, as expected.

I do not understand the difference.

+7
grails groovy
source share
1 answer

I hope I formulate it correctly

The groovy documentation at http://groovy.codehaus.org/Closures says that "Closing without →, ie {}, is a closing with one argument, which is implicitly called" this "....." In some cases you need to build Closure with zero arguments, for example using GString for templates, defining EMC property, etc. You must explain that your closure is like {->} instead of just {} "

In essence, your layout was trying to use "return" as an argument. You need to: → say "I do not have parameters for the transfer", and then put what you want it to return on the right side of the arrow

+9
source share

All Articles