DataTables with Context

22 views
Skip to first unread message

Alex

unread,
May 7, 2013, 9:44:39 PM5/7/13
to specs2...@googlegroups.com
Hi,

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 {

sequential

// 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 ;)

Alex

unread,
May 7, 2013, 10:13:20 PM5/7/13
to specs2...@googlegroups.com

etorreborre

unread,
May 7, 2013, 10:24:26 PM5/7/13
to specs2...@googlegroups.com
Please see my answer on StackOverflow.

Alex

unread,
May 7, 2013, 10:40:42 PM5/7/13
to specs2...@googlegroups.com
Thanks Eric,
I'm testing it now...

Alex

unread,
May 7, 2013, 10:53:06 PM5/7/13
to specs2...@googlegroups.com
Copy from stackoverflow:

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 } 
      }
    }
  }
}

or

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
      }
    }
  }
}

specs2 is awesome! ;)



Reply all
Reply to author
Forward
0 new messages