Created
February 18, 2013 03:15
-
-
Save jbrechtel/4974924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.specs2._ | |
import execute.AsResult | |
import mutable.Around | |
/* this scope is incidentally lazy since the singleton never gets constructed if code that uses it isn't executed */ | |
object databaseScope extends Around { | |
def setupDB { println("#####################\nBUILDING DATABASE\n#####################") } | |
setupDB | |
def around[T: AsResult](t: => T) = AsResult(t) | |
} | |
/* this scope is explicitly lazy */ | |
object lazyDatabaseScope extends Around { | |
lazy val setupDB = { println("#####################\nBUILDING DATABASE\n#####################") } | |
def around[T: AsResult](t: => T) = { | |
setupDB | |
AsResult(t) | |
} | |
} | |
class FooSpecification extends mutable.Specification { | |
"Some unit test" >> { | |
"I don't need the database" in {0 == 0} | |
} | |
} | |
class BarSpecification extends mutable.Specification { | |
"DB Stuff" >> { | |
"doesnt need database" in {0 == 0} | |
"connect to db" in lazyDatabaseScope {0 == 0} | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
} | |
} | |
class BazSpecification extends mutable.Specification { | |
"DB Stuff" >> { | |
"doesnt need database" in {0 == 0} | |
"connect to db" in lazyDatabaseScope {0 == 0} | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
"connect to db again" in lazyDatabaseScope { 0 == 0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment