How to specify a range instead of a list in the "where:" block of the Spock specification

The following code example:

class MySpec extends spock.lang.Specification { def "My test"(int b) { given: def a = 1 expect: b > a where: b << 2..4 } } 

produces the following compilation error: "where-blocks can only contain parameterizations (for example," salary <"[1000, 5000, 9000], salary = salary / 1000 ')"

but using a list instead of a range:

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

compiles and works fine as expected.

Can I also specify a range somehow?

+6
source share
1 answer

Using

 where: b << (2..4) 

The test can also be optimized as shown below. Note the lack of arguments for the test.

 def "My test"() { expect: b > a where: a = 1 b << (2..4) } 
+9
source

All Articles