Search code examples
scalaspecs2

How does containTheSameElementsAs work in specs2


This code does not match. Is this correct?

List(1, List(2, 3, List(4)), 5) must containTheSameElementsAs(List(5, List(List(4), 2, 3), 1))

Error message is following:

[error]   x be available for elements in a sequence
[error]    List(1, List(2, 3, List(4)), 5)
[error]      is missing: List(List(4), 2, 3)
[error]      must not contain: List(2, 3, List(4)) (specs2test.scala:98)

Solution

  • The containsTheSameElementsAs matcher only goes one level deep, so the match fails on your nested list as List(2, 3, List(4)) != List(List(4), 2, 3). It might be better to simply flatten your nested object before using this matcher.