AFTER GETTING COMMENTS, AND FIGURED OUT HOW IT WORKS, I STILL THINK:
Would be nice though, if specs2 provides non consumable logic, along with consumable for iterators. Like if I don't use iterator.size method directly, but use specs' method like: haveSize
I have a test, which has a code:
val ids = for(software <- parser) yield software.productID
//ids.size must_== 2;
ids.foreach(x => println(x))
It produces the output:
1
2
If I uncomment spec2 check (ids.size must_== 2
), it will provide with empty output.
It seems spec2, goes over iterator (ids) and then I end up with iterator that points to the end of data (empty iterator). Thus I can not use this iterator anymore - in next tests.
Shod spec2/test framework behave like this?
So, if I use test like this (by some reason):
ids.size must_== 2;
ids.size must_== 2;
It would fail.
//--
Here we use iterator's size() method. So, I've got that that's ok having behaviour like that. But if use code like this:
Ids.toIterable must haveSize(2); // here we do not use iterator.size() method dirrectly
for(id <- ids) println(id).
Prints nothing. It seems it still consumes my 'poor' iterator..
I found a work-around:
val (it1, it2) = ids.duplicate
it1.size must_== 2;
it2.size must_== 2;
And with this (convert to List), it will work also (like was suggested in comments):
val ids = for(software <- parser.toList) yield software.productID
But this exactly what spec2 could use by default (for methods like haveSize
). (i've posted a bug).