Following up on my recent post about creating a Spock specification to read the test data from a CSV file without loading all the data into the memory, I created a CSVReader that implements Iterable that allows me to pull this off. You may download the source code here.
With this implementation, I can now write an elegant Spock specification:-
class MySpockSpec extends Specification {
@Unroll
def "#firstNum + 1 == #secondNum"() {
expect:
Integer.valueOf(firstNum as String) + 1 == Integer.valueOf(secondNum as String)
where:
[firstNum, secondNum] << new CSVReader(getClass().getClassLoader().getResourceAsStream("test.csv"))
}
}
Leave a Reply