Spock Web Console

subscribe to the feed Subscribe
Demonstrate old() method (via #spockwebconsole)
tweet this script Tweet

Demonstrate old() method

Published 1 year ago by Warren Smith with tags old
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.Specification

class DemonstrateOldMethodSpec extends Specification {

    def list = ['1','2','3','4']
  
    def "test that size is 4"() {
        expect:
        list.size() == 4
    }

    def "Add two elements to the list and expect 6"() {
        when:
        list << '5'
        list << '6'

        then:
        list.size() == old(list.size()) + 2 // the old() method result is evaluated before the when block
    }
}