Skip to content

Instantly share code, notes, and snippets.

@jaceklaskowski
Created January 28, 2015 23:08
Show Gist options
  • Save jaceklaskowski/3d961cfd1de8446524ca to your computer and use it in GitHub Desktop.
Save jaceklaskowski/3d961cfd1de8446524ca to your computer and use it in GitHub Desktop.
specs2 DataTables
import org.specs2._

class HelloSpec extends Specification with matcher.DataTables { def is =
  "adding integers should just work in scala"  ! e1

  def e1 =
    "a"   | "b" | "c" |                                   // the header of the table, with `|` separated strings
     2    !  2  !  4  |                                   // an example row
     1    !  1  !  2  |> {                                // the > operator to "execute" the table
     (a, b, c) =>  a + b must_== c                        // the expectation to check on each row
  }

}

Why does the following summary show + after the name of the spec?

[info] HelloSpec+ adding integers should just work in scala
[info] Total for specification HelloSpec
[info] Finished in 11 ms
[info] 1 example, 0 failure, 0 error
[info]
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 1 s, completed Jan 29, 2015 12:05:44 AM
@etorreborre
Copy link

That's because you are not using interpolated strings. Try this:

class HelloSpec extends Specification with matcher.DataTables { def is = s2"""
  adding integers should just work in scala  $e1
"""
  def e1 =
    "a"   | "b" | "c" |                                   // the header of the table, with `|` separated strings
     2    !  2  !  4  |                                   // an example row
     1    !  1  !  2  |> {                                // the > operator to "execute" the table
     (a, b, c) =>  a + b must_== c                        // the expectation to check on each row
  }
}

Otherwise, when you use ! this is the low level API and you have to insert newlines yourself:

class HelloSpec extends Specification with matcher.DataTables { def is =
  br ^
  "adding integers should just work in scala"  ! e1

  def e1 =
    "a"   | "b" | "c" |                                   // the header of the table, with `|` separated strings
     2    !  2  !  4  |                                   // an example row
     1    !  1  !  2  |> {                                // the > operator to "execute" the table
     (a, b, c) =>  a + b must_== c                        // the expectation to check on each row
  }
}

@jaceklaskowski
Copy link
Author

It's a copy and paste from http://etorreborre.github.io/specs2/guide/org.specs2.guide.Matchers.html#DataTables. Should the example be fixed then?

@etorreborre
Copy link

Absolutely, I'll fix that. There was an evolution a few versions ago in terms of how things are being displayed, after the introduction of s2 strings but I didn't think of checking the corresponding doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment