scala - In the specs2 framework, why does using a Scope prevent execution of a forAll quantifier? -


in code below, how can make specs2 execute first test? "print ones" test passes when should fail. code inside forall() section not executing because of new scope.

the println statements tracing output. please let me know if see lines starting "one".

the empty scope demonstrating problem. stripped-down code use variables in scope.

import org.scalacheck.gen import org.scalacheck.prop._ import org.specs2.scalacheck import org.specs2.mutable.specification import org.specs2.specification.scope  class testingspec extends specification scalacheck {   "sample test" should {     "print ones" in new scope {        println("the first test passes, should fail")       forall(gen.posnum[int]) { (x: int) =>           println("one: " + x)           (0 < x) mustnotequal true       }      }       "print twos" in {        println("the second test passes , prints twos")       forall(gen.posnum[int]) { (x: int) =>         println("two: " + x)         (0 < x) mustequal true       }      }    } } 

here output:

sbt> testonly testingspec second test passes , prints twos first test passes, should fail two: 1 two: 2 two: 1     ... two: 50 two: 34 two: 41 [info] testingspec [info]  [info] sample test should [info]   + print ones [info]   + print twos [info]  [info] total specification testingspec [info] finished in 96 ms [info] 2 examples, 101 expectations, 0 failure, 0 error [info]  [info] passed: total 2, failed 0, errors 0, passed 2 [success] total time: 3 s, completed apr 28, 2015 3:14:15 pm 

p.s. updated project dependency version 2.4.15 specs2 3.5. still has issue...

this because put in scope must throw exceptions when there failure. scalacheck prop not unless execute example passing.

the workaround transform prop specs2 result using following implicit example:

import org.specs2.execute._  implicit class runprop(p: prop) {   def run: result =      asresult(p) } 

then

"print ones" in new scope {    println("the first test passes, should fail")    forall(gen.posnum[int]) { (x: int) =>      println("one: " + x)       (0 < x) mustnotequal true    }.run  }  

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -