I think you seem to confuse the result of a closure and the result of a
method. In your first example,
mockArray.collect(invoke { it.name.returns("a name") }.returns("apple",
"arts"))
["apple", "arts"] should be the result of 'collect' instead of the
closure. So, it should be
mockArray.collect(invoke { it.name.returns("a name") }).returns("apple",
"arts")
The second example is correct. The last example should be
array.sort( invoke(10, 20).shouldReturns(true) ).returns(20, 15, 10, 5)
I still suggest to use an optional 'should' property like:
array.sort( invoke(10, 20).should.returns(true) ).returns(20, 15, 10, 5)
What's more, I think we should talk about the 'it' keyword. Because 'it'
is a parameter of the closure, actually users should use
'invoke(aMockObject) {}' to mock 'it', but it is inconvenient to do so.
So I suggest: If users haven't provide a parameter for 'invoke', then
pass the mock object to the closure as a parameter.
And, I still insist on allowing using the 'delegate' keyword for closure
mocking. In your second example, 'def root = run("ls /")' is actually
'def root = delegate.run("ls /")', so it will be more consistent to
write 'delegate.run("ls /").returns(["etc", "var", "tmp"])', or just
'run("ls /").returns(["etc", "var", "tmp"])'
在 2009-05-08五的 00:05 -0700,Julien写道: