Reading http://spockframework.github.io/spock/docs/1.0/data_driven_testing.html, it seems that data tables are a convenient, readable way to structure test inputs. I'd like to structure my test output in a similar way.
I have a method under test which returns an Iterable<Entry<String, String>>
. I have the following Spock test case, but something tells me there is a way I can make Spock do more of this for me. This is essentially just Java code, so I suspect there is a groovier way. Can this be simplified?
def "iterate" () {
given:
Iterator expected =
['one' : 'a',
'two' : 'b',
'three' : 'c',
'four' : 'd',
'five' : 'e',
'six' : 'f'].entrySet().iterator()
when:
Iterable<Entry<String, String>> actual = testClass.method()
then:
for (def entry : actual) {
assert entry == expected.next()
}
}