These are chat archives for etorreborre/specs2

1st
Jun 2016
drhumlen
@drhumlen
Jun 01 2016 11:33
When using a table, is it possible to represent the value-cells the way you want? Right now, if the spec fails, it just uses .toString on the when rendering the table, right? Would be nice if I could use either the .aka(".....") or define some typeclass instance implicit val personShow = new Show{... = person.name + " of age " + person.age
The DataTables are very handy, and I've started using them a lot, but I need to customize how the values are rendered somehow. Because often, you'll get a gigantic .toString filled with irrelevant data, making it impossible to see what failed, and even which row that failed.
Eric Torreborre
@etorreborre
Jun 01 2016 12:08
@drhumlen this is a known issue and the only work-around at the moment is to wrap your values into new types which provide a better toString method
case class MyLongString(s: String) { override def toString = s.take(10)+”…” }
implicit class ToMyLongString(s: String) { def long: MyLongString(s) }
“long strings” | “are long” |>
(“x”*30).long | 10 | { (sl, n) => sl.s.size must be_>=(n) }
This message was deleted
Eric Torreborre
@etorreborre
Jun 01 2016 12:14
@drhumlen this is not ideal but threading through Show instances will not be a small refactoring. If you want to PR this :-)...
drhumlen
@drhumlen
Jun 01 2016 12:26

Hmm... I'll experiment with that ^, but I'm also leaning towards doing something like this instead:
tester(2, 2, 4)
tester(2, 8, 10)

def tester(a: Int, b: Int, res: Int) = { "the number $a | the number $b | outputs $c" >> { (a+b) must _== c } }

ie. making a helper function that generates examples with text ^. (the examples here with numbers doesn't make any sense, but we have som huuge case class structures)

It would be cool if tables got the Show[]-functionality first, but it's probably still quite a job to implement ;) Would be fun to PR, but I don't think I'm capable (yet). Off-topic: do you have any plans of switching from scalaz to cats (in specs2)?
Eric Torreborre
@etorreborre
Jun 01 2016 12:38
I don’t have any plans yet to do that switch. It would be a huge thing to do and I don’t see what would be the benefits. How would that help you?
drhumlen
@drhumlen
Jun 01 2016 13:25
I was just curious since so many seem to prefer cats over scalaz these days. I don't think it would affect me though -- other than maybe if people already have cats.Show[]-instances of stuff, they could reuse it in their tests if the Show[]-behaviour became a thing
drhumlen
@drhumlen
Jun 01 2016 14:39
... Come to think about it.... What I actually want is something very different. When doing table tests, I actually want to see the code-row that failed exactly as it is in the sourcecode of my test. So I want to see the variable name, not the .toString of the value..... Which is very similar to the eg { ... }-function I believe..? Is there a way to do the same as eg but in a tabular fashion? Maybe it's less dramatic change than making a Show[]-system?
Eric Torreborre
@etorreborre
Jun 01 2016 15:03
This is possible if you use an immutable spec and don’t provide a description for your example on the same line
s2”””
   My table must be ok
     ${
        <data table here> 
       }
“””