Muki-SkyWalker / specs

Automatically exported from code.google.com/p/specs
Other
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 [T](T)List[T]
[error]  and method identity in object Predef of type [A](A)A
[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.

Original issue reported on code.google.com by savedfas...@gmail.com on 7 Feb 2010 at 3:55

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by etorrebo...@gmail.com on 8 Feb 2010 at 12:20

GoogleCodeExporter commented 9 years ago
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?

Original comment by savedfas...@gmail.com on 8 Feb 2010 at 3:43

GoogleCodeExporter commented 9 years ago
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(<test></test><secondtest></secondtest>) 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.

Original comment by etorrebo...@gmail.com on 10 Feb 2010 at 1:51

GoogleCodeExporter commented 9 years ago
Wow, complicated hehe.

So wait, what eventually helped to reproduce it?

Original comment by savedfas...@gmail.com on 10 Feb 2010 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by etorrebo...@gmail.com on 26 May 2010 at 10:26