scala – Using specs matchers in scalacheck properties – Education Career Blog

I’m trying to use specs mathers inside scalacheck properties. For example, I have a matcher that works like this:

x must matchMyMatcher(y)

When I want to use this matcher inside scalacheck property, I do the following:

import org.scalacheck._
import org.specs._
val prop = Prop.forAll(myGen){
    (x,y) => new matchMyMatcher(x)(y)._1
prop must pass

Unfortunately, in this case I have erasure of debug information that I putted in matcher and that I need when property fails.
Is there a stipulated way to use matchers inside props?


You will get the proper failure message if you use “must” with your matcher:

val gen = Gen.oneOf(("a", "a"), ("b", "b2"))
val function = (pair: (String, String)) => pair._1 must myMatcher(pair._2)
gen must pass(function)

Then, in that case your example should fail with:

> A counter-example is '(b,b2)': 'b' is not equal to 'b2' (after 0 tries)

Leave a Comment