225035 (5) [Avatar] Offline
#1
I've come across some Spock code that is of the form:
 with (object1, {
              !member1
              member2 == SomeEnum.ENTRY1.name()
              member3 == SomeEnum.ENTRY2.name()
              isBooleanMember
        })


Here the with clause has an object followed by a comma before the opening brace. What is the difference, if any, of having a comma follow the object being evaluated?
Kostis Kapelonis (63) [Avatar] Offline
#2
Hello

It is exactly the same. This is not a Spock feature, but rather a Groovy feature.
Groovy allows you to omit parentheses and also take the closure out of them if it is the last argument.

The following are all equal:

with(warehouseInventory) {
		!isEmpty()
		getBoxesMovedToday() == 3
		availableOfProduct("toshiba") == 2
		availableOfProduct("panasonic") == 3
		availableOfProduct("jvc") == 2
	}

with warehouseInventory, {
		!isEmpty()
		getBoxesMovedToday() == 3
		availableOfProduct("toshiba") == 2
		availableOfProduct("panasonic") == 3
		availableOfProduct("jvc") == 2
	}

with(warehouseInventory, {
		!isEmpty()
		getBoxesMovedToday() == 3
		availableOfProduct("toshiba") == 2
		availableOfProduct("panasonic") == 3
		availableOfProduct("jvc") == 2
	})



For simplicity I have chosen only one style for the book. Feel free to choose the one you like, but if you work in a team make sure
that everybody agrees on your selection.

For more information see

http://mrhaki.blogspot.gr/2009/11/groovy-goodness-passing-closures-to.html
http://mrhaki.blogspot.gr/2009/10/groovy-goodness-optional-parenthesis.html
http://groovy-lang.org/style-guide.html
225035 (5) [Avatar] Offline
#3
Thank you!