Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Created October 23, 2013 04:08
Show Gist options
  • Save etorreborre/7112484 to your computer and use it in GitHub Desktop.
Save etorreborre/7112484 to your computer and use it in GitHub Desktop.
Stack Around contexts
import org.specs2._
import matcher._
import execute._
import specification._
// the "larger" context must be mixed-in last
class MySpec extends mutable.Specification with Db with Web {
// prints
// on the web
// in the db
//run
"run in the db, on the web" >> { "run".pp; ok }
}
trait AroundBase extends AroundExample {
def around[R : AsResult](r: =>R) = {
AsResult(r)
}
}
trait Db extends AroundBase {
override def around[R : AsResult](r: =>R) = {
println("in the db")
AsResult(super.around(r))
}
}
trait Web extends AroundBase {
override def around[R : AsResult](r: =>R) = {
println("on the web")
AsResult(super.around(r))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment