Closed GoogleCodeExporter closed 9 years ago
The core problem is that Spock verifies interactions as they happen, not after
the fact. (An interaction declared in a then-block is effectively moved to a
setup-block.) And at the time `method` is called, `doStuff` hasn't yet returned
a value. To solve this problem, you'll need to capture the value passed to
`method`, and compare it to the value returned from `doStuff` in an assertion.
For further information, see http://docs.spockframework.org.
Original comment by pnied...@gmail.com
on 29 Mar 2014 at 6:39
Using your advice, I came up with the following that works. Is this what you
had in mind? It seems to only work if `valueUsedByDoStuff` is declared in the
'given' block.
def "what was suggested by Spock maintainer"() {
given:
String valueUsedByDoStuff
MyClass myClass = new MyClass()
myClass.dependency = Mock(MyDependency)
when:
String value = myClass.myMethod()
then: "doStuff is called once with the value returned from myMethod"
1 * myClass.dependency.doStuff({ valueUsedByDoStuff = it })
valueUsedByDoStuff == value
}
Original comment by abl...@commercehub.com
on 29 Mar 2014 at 5:35
Original issue reported on code.google.com by
abl...@commercehub.com
on 28 Mar 2014 at 9:07