These are chat archives for etorreborre/specs2

8th
Nov 2016
drhumlen
@drhumlen
Nov 08 2016 10:30

How can I use a .showAs on the right-hand side too when doing a must_== ?

3.showAs("The number " + _) must_== (2+1).showAs("The number " + _) I get the result:

[info] x Testing .showAs
[error]    The number 3 is not equal to 'org.specs2.matcher.ThrownExpectations$$anon$2@c96ee16' (Example.scala:77)
[error] Expected: org.specs2.matcher.ThrownExpectations$$anon$2@c96ee16
[error] Actual:   3
Eric Torreborre
@etorreborre
Nov 08 2016 11:22
Basic answer is "you can not". You need to define a new matcher for this
def beSameNumber(expected: Int): Matcher[Int] = { actual: Int => 
   (actual == expected, s"The number $actual is not the same as the number $expected")
}
drhumlen
@drhumlen
Nov 08 2016 12:56

Aha. Thanks! :)

Although, it would be awfully nice to have some sort of Show implicits system, so that you always could specify how to render different types. In our project, we sometimes need to compare lists of huge data structures; so printing the whole thing becomes a huge mess. In those cases, it would be super nice to use just the ie name/title Show[Document](_.title) instead of printing out all the irrelevant fields too. (As a subtle future feature request)

Eric Torreborre
@etorreborre
Nov 08 2016 13:38
There's some work started to provide better differences: etorreborre/specs2#500. Maybe we can reuse this in your case to display exactly what you need