mardi 18 août 2015

Scalatest: have a test which is valid if one of both matchers matches

I am having a hard time having an or relation between to matchers on an case class which match on different methods/fields of given class.

I know I could do it with exists an || which would end up with a Bool but will erase all Feedback from the testing Framework which I do not want.

Here is an example of what I would like to do:

class ExampleSpec extends FunSpec with Matchers {

  case class Element(count: Int,  value: String)

  val data : List[Element] = List(
    Element(0, "ok"),
    Element(5, "")
    Element(0,""),
    Element(1, "a")
  )

  describe("My data test") {
    data foreach {d =>
        it("valid data either has a count > 0 or the value is not empty") {
          d.count should be > 0 or d.value should not be empty // I have no idea how to get the or working
        }

    }
  }
}

Aucun commentaire:

Enregistrer un commentaire