Better diagnostics when types doesn't match

12 views
Skip to first unread message

Jeppe Nejsum Madsen

unread,
Mar 14, 2012, 11:50:02 AM3/14/12
to specs2...@googlegroups.com
Hi,

Sometimes when writing new code, I often get failures such as this:

java.lang.Exception:
'VehicleCreated(00000000-0000-002a-0000-00000000002a,vin,lp)' is not
equal to 'VehicleCreated(00000000-0000-002a-0000-00000000002a,vin,lp)'

which is not very informative :-) I guess this is usually caused (at
least for me) by the values being different types but yielding the
same toString output. Perhaps it's possibly to augment the error with
type info if the two string representations are the same. Wdyt?

I know about the ==== matcher but I don't like the way it reads, e.g.

events ==== VehicleCreated(fixedId, "vin", "lp")

doens't really say that we're asserting something....

/Jeppe

etorreborre

unread,
Mar 14, 2012, 4:02:37 PM3/14/12
to specs2...@googlegroups.com
In your example, is it really VehicleCreated which has different types or is VehicleCreated a case class containing elements with the same toString representation but different types? 

The first case should actually be handled already by the be_== matcher (unless there's a regression, I know I changed this code lately).

Jeppe Nejsum Madsen

unread,
Mar 14, 2012, 4:14:23 PM3/14/12
to specs2...@googlegroups.com
On Wed, Mar 14, 2012 at 9:02 PM, etorreborre <etorr...@gmail.com> wrote:
> In your example, is it really VehicleCreated which has different types or is
> VehicleCreated a case class containing elements with the same toString
> representation but different types?
>
> The first case should actually be handled already by the be_== matcher
> (unless there's a regression, I know I changed this code lately).

events is actually a List so the following worked

events must_== List(VehicleCreated(...))

It's just a little hard to figure out when the string representations
are the same. Not sure why they print the same though...

/Jeppe

etorreborre

unread,
Mar 14, 2012, 6:22:10 PM3/14/12
to specs2...@googlegroups.com
Could you please post a small example?

With 1.9-SNAPSHOT:

import org.specs2.mutable.Specification

class TestSpec extends Specification {
  "h" >> {
    List(V(1, 2)) === V(1, 2)
  }
}
case class V(a: Int, b: Int)

I get:

'V(1,2)': anon is not equal to 'V(1,2)': examples.V

E.

Jeppe Nejsum Madsen

unread,
Mar 15, 2012, 5:18:41 AM3/15/12
to specs2...@googlegroups.com
Ahh **facepalm**

During all the switching back & forth between 1.8.2 and 1.9-SNAPSHOT i
forgot to update my eclipse project!

1.9-SNAPSHOT behaves exactly like I would like. Thanks for reading my mind :-)

/Jeppe

Reply all
Reply to author
Forward
0 new messages