Using Specs2, if I do:
1 must beEqualTo(2)
1 must beEqualTo(1)
The test fails (as expected)
If I do:
Result.foreach(1 to 10) { i =>
i must_== 2
}
Result.foreach(1 to 10) { i =>
i must_== i
}
The test passes
For Result.foreach I have to use and to make the test fail (as expected):
Result.foreach(1 to 10) { i =>
i must_== 2
} and
Result.foreach(1 to 10) { i =>
i must_== i
}
Why is this?
Is there a way to make it work in a less surprising way? This is very error prone - it's way too easy to not notice somebody didn't type and
I checked the Specs2 user guide but there's no mention of this behaviour that I can find.
This should probably be better documented. The
Result.foreachfunction is indeed supposed to be non side-effecting. If you want side-effects you can callforeachdirectly in your specification because this one is wired in with the "throwing" behaviour of a mutable specification:returns