Spock: Argument capture and return value in 1.3-RC1

Created on 31 Jan 2019  路  1Comment  路  Source: spockframework/spock

In the 1.3-RC1 release docs, this breaking change is announced:

def extern = null
1 * mock.foo( { extern = it; it.size() > 0 })  // old
1 * mock.foo( { it.size() > 0 }) >> { extern = it[0] } // new

What if I have ...

def extern = null
def bar = new Bar()
1 * mock.foo({ extern = it }) >> bar

... how does that translate to the new format?

/cc: @leonard84

Most helpful comment

Just return bar from the closure

def extern = null
def bar = new Bar()
1 * mock.foo(_) >> { extern = it[0] ; bar }

>All comments

Just return bar from the closure

def extern = null
def bar = new Bar()
1 * mock.foo(_) >> { extern = it[0] ; bar }
Was this page helpful?
0 / 5 - 0 ratings