Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a Range instead of List in the 'where:' block of a Spock specification

Tags:

groovy

spock

The following example code:

class MySpec extends spock.lang.Specification {
    def "My test"(int b) {
        given:
        def a = 1

        expect:
        b > a

        where:
        b << 2..4
    }
}

throws the following compilation error: "where-blocks may only contain parameterizations (e.g. 'salary << [1000, 5000, 9000]; salaryk = salary / 1000')"

but using a List instead of a Range:

        where:
        b << [2,3,4]

compiles and runs fine as expected.

Could I also specify a Range somehow?

like image 503
AndrewW Avatar asked Jan 17 '14 00:01

AndrewW


1 Answers

Use

where:
b << (2..4)

The test can be optimized as below as well. Note no arguments to the test.

def "My test"() {
  expect:
  b > a

  where:
  a = 1
  b << (2..4)
}
like image 67
dmahapatro Avatar answered Oct 11 '22 14:10

dmahapatro