QuickTip (Spock): Don't use .each in a then block!!!
This happens time and time again. QA finds a bug and I swear I wrote a test for that condition. So, I go back to try to debug that test. I see the original test I wrote and the condition that should fail. It looks something like this: when: List<SomeType> someResults = service.someAction(someParam) then: someResults // assert the result is not null, empty list, etc someResults.each { it.someFieldName == 'someValue' it.someOtherFieldName == 1 } In this case, someOtherFieldName is empty but the test still passes... wtf?! right? Well, this is actually the expected behavior. Because each doesn't actually return anything from the closure but just returns the collection itself, Spock thinks it is fine. It doesn't care about the lines within the each block and whether they fail or not. So we have a few choices here: use .every (only applies to the last line) when: List<SomeType> someResults = service.someAc...