Search code examples
scalascalatest

Scalatest matching options


I have this simple test:

test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = luceneService.buildCategoryTree(path)
    actual shouldEqual expected
}

And I get this failure:

Some(Array("/home")) did not equal Some(Array("/home"))

How can this be?

As I understand it the docs state that I should be able to use options in tests

If I change the test to

actual.get shouldEqual expected.get

it passes


Solution

  • Looks like there is a bug with the matchers. Using Seq instead of Array works:

    val expected = Some(Seq("/home"))
    val actual = luceneService.buildCategoryTree(path).map(_.toSeq)
    actual shouldEqual expected