Spock Web Console

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


Published 1 year ago by Eric
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*

With variables we can store values of types to use later.

Try to answer these questions on variables.
class VariablesSpec extends Specification {
    def "Variables"() {
        when:"basic assignment"
        def foo = 1
        then:"What does foo equal?"
        foo == null

        when:"complex assignment"
        def bar = 1 * 2
        then:"What does bar equal?"
        bar == null

        when:"using variables"
        def baz = foo + bar
        then:"What does baz equal?"
        baz == null

        when:"What happens when we add two strings?"
        def fizz = "fizz"
        def buzz = "buzz"
        fizz + buzz == null

        def bazz = 3
        bazz = "three"
        then:"What will bazz be?"
        bazz == null