I am trying to define some context so that it is executed for each row of the data table (before the statement is executed on each row).
I found this example, but for life I can’t understand how to write a complete set of tests. I would like to define the context once and share it with all the examples. Here is roughly what I have:
class SomeSuite extends Specification with DataTables { // TODO: define context somehow??? // val context = new Before { println("BEFORE") } "test 1" should { "do something" in { context | "col1" | "col2" | val1 ! val2 | val3 ! val4 |> { (a, b) => //some assertion with (a, b) } } } }
I would like to see that "DO" is printed every time (only 2 times) before each statement with (a, b).
I would really appreciate any help.
Thanks;)
Thanks Eric, here is my last code. I only added “implicit” as the context is used for many tests:
class SomeSuite extends Specification with DataTables { implicit val context = new Before { def before = println("BEFORE") } "test 1" should { "do something" in { "col1" | "col2" | val1 ! val2 | val3 ! val4 |> { (a, b) => a must_== b // this is wrapped with context } } } }
source share