These are chat archives for etorreborre/specs2

31st
Mar 2016
Eric Torreborre
@etorreborre
Mar 31 2016 06:25
@khronnuz you want to log the state both when it passes and fails? There is no finally but you can always enclose your code in try xxx finally yyy to do this
Johnny Everson
@everson
Mar 31 2016 06:29
@etorreborre yes, would like to log the value of state in any case. By failing I mean not fulfilling the conditions. It does not throw anything.
Eric Torreborre
@etorreborre
Mar 31 2016 06:29
@petomat datatables should definitely be printed on the console. I recently fixed etorreborre/specs2#466 related to datatables in html and did a fix for the console reporting as well. Please try 3.7.2-20160324133853-454b358
@khronnuz why not use try / finally then?
Johnny Everson
@everson
Mar 31 2016 06:30
because I hadn't thought of it. Will try. Thanks :).
Eric Torreborre
@etorreborre
Mar 31 2016 06:31
@khronnuz now if this is something you need to do for several tests you might want to use the ForEach trait
Johnny Everson
@everson
Mar 31 2016 06:32
I actually do, so, that is a good idea.
Eric Torreborre
@etorreborre
Mar 31 2016 06:33
but that only works if you pass the same data, stateCounter, to each test because ForEach is a ForEach[T] where T is some piece of data passed to each test
Johnny Everson
@everson
Mar 31 2016 06:34
I figured that. thanks. Might still work.
Peter Schmitz
@petomat
Mar 31 2016 08:51

@etorreborre Thank you! But how can I make the first line of the table (heading) be on a separate line in the output?

class DTSpec extends Specification with DataTables {

  def is = s2"""
Some table description

$table
"""

  def table: DecoratedResult[DataTable] =
    "a"     || "b"     | "c"         |>
    "hello" !! "you"   ! "hello you" |
    "you"   !! "hello" ! "you hello" |
    "y"     !! "h"     ! "y h"       | { (a, b, c) =>  a+" "+b must_== c }

}

gives

[info] DTSpec
[info] Some table description  | a     | b     | c         | 
[info] + | hello | you   | hello you | 
[info] + | you   | hello | you hello | 
[info] + | y     | h     | y h       |
new line chars in s2 string didn't worked out for me.
Peter Schmitz
@petomat
Mar 31 2016 09:19
And if $table is on the same (end of) line as "some table description" no datatable will be printed out.
In case of failure everything is printed out fine.
Peter Schmitz
@petomat
Mar 31 2016 09:44
And by the way. Is there a way to supply a custom to string conversion for each column / type when printing the table?
Eric Torreborre
@etorreborre
Mar 31 2016 09:56
@petomat formatting is really hard to get right in all cases… This is probably a bug and I’m not sure how hard it is to fix it. In the meantime you can work-around it by adding a “paragraph” Fragment after Some table description $p
Peter Schmitz
@petomat
Mar 31 2016 10:14
Cool, that worked as a quick fix. Thanks!