Export to GitHub

specs - issue #117

have size (2) and haveSize(2) fail with strange errors on a NodeSeq


Posted on Feb 7, 2010 by Swift Bird

Run the attached spec to see the problem.

must have size(2) produces a:

java.util.NoSuchElementException: head of empty list

While must haveSize(2) produces:

[error] /Users/Shadowfiend/openstudy/openstudy- scala/src/test/scala/com/openstudy/snippet/HelloWorldTest.scala:18: ambiguous implicit values: [error] both method anyToList in trait Products of type TList[T] [error] and method identity in object Predef of type AA [error] match expected type (scala.xml.Group) => AnyRef{def size: Int} [error] Group(<test></test><secondtest></secondtest>) must haveSize(2)

To get the spec to run correctly, I had to call toList on the NodeSeq, but I got the feeling that it should work without that.

Attachments

Comment #1

Posted on Feb 8, 2010 by Massive Giraffe

Hi,

Which version of specs are you using?

I could not reproduce the NoSuchElementException with any of 1.6.2 (scala 2.7.7) or with 1.6.3 (scala 2.8.0)

On the other hand I can tell you that the compilation error is due to the import of the Sugar object implicits. In that object there is a function to transform all tuples to a list, including a single element. This conflicts here with the identity method in Predef. If you remove that you should have to call toList on the NodeSeq.

Comment #2

Posted on Feb 8, 2010 by Swift Bird

Hm. I figured that the compilation error was due to something similar. I'm obviously a slight bit of a newb to Scala, but isn't it smart enough to figure out that haveSize(2) is a method call, rather than the creation of a tuple? Silly question, of course: obviously, it isn't :-P

I'm running specs 1.6.2 with scala 2.7.7. This wouldn't have anything to do with running through sbt, would it?

Comment #3

Posted on Feb 10, 2010 by Massive Giraffe

Further analysis on the NoSuchElementException shows that you've been bitten (my fault certainly) by implicits.

Since there is a method in the Sugar object to convert anything to a List. If I write:

val x = Group() must have

then x is of type org.specs.specification.Result[Group] and converted to a List, it has a size method. Which returns an Integer, which is converted to a list of one element again, and then fails when trying to get the element at position 2.

I fixed the issue anyway and the fix is available in specs-1.6.2.1-SNAPSHOT:

http://nexus-direct.scala-tools.org/content/repositories/snapshots/org/scala- tools/testing/specs/1.6.2.1-SNAPSHOT/specs-1.6.2.1-SNAPSHOT.jar.

Comment #4

Posted on Feb 10, 2010 by Swift Bird

Wow, complicated hehe.

So wait, what eventually helped to reproduce it?

Comment #5

Posted on May 26, 2010 by Massive Giraffe

(No comment was entered for this change.)

Status: Verified

Labels:
Type-Defect Priority-Medium Milestone-1.6.4