Skip to content

Instantly share code, notes, and snippets.

@prystupa
Created August 25, 2013 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prystupa/6333591 to your computer and use it in GitHub Desktop.
Save prystupa/6333591 to your computer and use it in GitHub Desktop.
package com.prystupa
import org.scalatest.{Tag, FunSpec}
import scala.collection.mutable
trait JasmineSpec extends FunSpec {
private val itWord = new ItWord
private val setup: mutable.Stack[List[() => Unit]] = mutable.Stack()
private val tearDown: mutable.Stack[List[() => Unit]] = mutable.Stack()
protected def beforeEach(code: => Unit) {
val list = (() => code) :: setup.pop()
setup.push(list)
}
protected def afterEach(code: => Unit) {
val list = (() => code) :: tearDown.pop()
tearDown.push(list)
}
protected override def describe(description: String)(fun: => Unit) {
setup.push(List())
tearDown.push(List())
super.describe(description)(fun)
tearDown.pop()
setup.pop()
}
protected override val it = observe
private lazy val observe: ItWord = new ItWord {
override def apply(specText: String, testTags: Tag*)(testFun: => Unit) {
val before = setup.reverse.flatMap(_.reverse)
val after = tearDown.flatMap(_.reverse)
itWord(specText, testTags: _*) {
before.foreach(_())
testFun
after.foreach(_())
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment