I'm trying to define some context so that it's executed for each row of data table (before assertion is run on each row).
I've found this example but for the life of me I can't figure out how to write the full test suite. I'd like to define context once and share it with all 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'd like to see "BEFORE" printed each time (total 2 times) before each assertion with (a, b).
I would really appreciate any help.
Thanks ;)
Thanks to Eric here is my final code. I only added 'implicit' since context is shared 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
}
}
}
}
The easy way is to use the apply
method of a Context
class SomeSuite extends Specification with DataTables {
val context = new Before { def before = println("BEFORE") }
"test 1" should {
"do something" in {
"col1" | "col2" |
val1 ! val2 |
val3 ! val4 |> { (a, b) =>
context { a must_== b }
}
}
}
}