It's not a method, it's a closure, so you really want…
controller.getApps() >> { "test" }
This will still return a string. To return a closure, use:
controller.apps >> { { -> "test" } } // or getApps()
Cheers,
Peter
So Spock understands closures as a mechanism for lazy evaluation?
e.g.
class T {
def getFoo() {
1
}
}
T t = Mock()
def bar = 1
t.getFoo() >> { bar }
t.foo == 1
bar = 2
t.foo == 2
?
Yes, I guess you could call it lazy initialization. It allows you to perform an arbitrary action in response to a method call. A common use case is throwing an exception.
Cheers,
Peter