Spock Web Console

subscribe to the feed Subscribe
Sometimes You Need Asserts - 2 (via #spockwebconsole)
tweet this script Tweet

Sometimes You Need Asserts - 2

Published 5 months ago by Michael Delaney with tags with
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*

class SometimesYouNeedAsserts extends Specification {
    class Fakey {
        String val
        String val2
    }

    def "With blocks don't play nice with Spock"() {
        given: "More Fakeys!"
        def fakeys = [new Fakey(val:'foo', val2:'bar'), new Fakey(val:'foo', val2:'bar'), new Fakey(val:'foo', val2:'bar')]

        expect: "This test will fail, but it will fail with a MultipleCompilationErrorsException, which isn't what we want"
        fakeys[0].with {
            val == 'foo'
            val2 == 'notbar'
        }
    }

    def "There is a built in with method in Specification"() {
        given: "I'm so sick of Fakeys"
        def fakeys = [new Fakey(val:'foo', val2:'bar'), new Fakey(val:'foo', val2:'bar'), new Fakey(val:'foo', val2:'bar')]

        expect: "This will fail with a useful message!"
        with(fakeys[0]) {
            val == 'foo'
            val2 == 'notbar'
        }
    }
}