Spock Web Console

subscribe to the feed Subscribe
Stubbing issue (via #spockwebconsole)
tweet this script Tweet

Stubbing issue

Published 2 years ago by topr with tags issue stub collection closure
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*
 
class StubbingIssueSpec extends Specification {
 
    def 'stub a method with collection as argument'() {
        given:
        def input = [1, 2, 3]
        def capturedArgument
        List listStub = Stub()
        listStub.addAll(input) >> { Collection coll ->
            capturedArgument = coll
        }
 
        when:
        listStub.addAll(input)
 
        then:
        input.class == capturedArgument.class
    }
}