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
Written by Danilo Tuler
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#