These are chat archives for etorreborre/specs2

27th
Nov 2016
Eric Torreborre
@etorreborre
Nov 27 2016 14:22

@edmondo1984 you can do this

import org.specs2.Specification
import org.specs2.main.Arguments
import org.specs2.specification.BeforeAll
import org.specs2.specification.core.Fragments

class MasterSpec extends Specification with BeforeAll { def is =

  "parent spec".title ^ br ^
  Fragments.foreach(List(new Spec1, new Spec2)) { s =>
    link(s) ^ br
  }

  def beforeAll =
    List(new Spec1, new Spec2).foreach(s =>
      specs2.run(s)(Arguments("console", "html")))

}

class Spec1 extends Specification { def is = s2"""
  test1 $ok
"""
}

class Spec2 extends Specification { def is = s2"""
  test2 $ok
"""
}

This runs the children specifications first and then the parent specification summarizing the run

[info] Spec1
[info]   + test1
[info]
[info] Total for specification Spec1
[info] Finished in 230 ms
1 example, 0 failure, 0 error
[info]
[info] Spec2
[info]   + test2
[info]
[info] Total for specification Spec2
[info] Finished in 123 ms
1 example, 0 failure, 0 error
[info]
[info] parent spec
[info] + Spec1
[info] + Spec2
[info]
[info]
[info] Total for specification parent spec
[info] Finished in 686 ms
[info] 2 specifications, 2 examples, 3 expectations, 0 failure, 0 error