Created
April 6, 2011 00:49
-
-
Save etorreborre/904913 to your computer and use it in GitHub Desktop.
A complete example of using Around
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
/** | |
* For those examples using Around may not be very different from a simple method call with a call-by-name | |
* parameter. | |
* | |
* The only difference is that the http object is a named context that you can compose with other setups, like a Before setup: | |
* | |
* http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Composing+contexts | |
*/ | |
class AcceptanceSpec extends Specification { def is = | |
"This specification has examples which must be executed inside an http session" ^ | |
"Example 1 is executed inside the session" ! http(e1)^ | |
"Example 2 is also executed inside the session" ! http(e2)^ | |
end | |
def e1 = success | |
def e2 = success | |
object http extends Around { | |
def around[T <% Result](t: =>T) = openHttpSession("test") { | |
t // execute t inside a http session | |
} | |
} | |
} | |
class UnitSpec extends org.specs2.mutable.Specification { | |
"This specification has examples which must be executed inside an http session" >> { | |
"Example 1 is executed inside the session" >> http { | |
success | |
} | |
"Example 2 is also executed inside the session" >> http { | |
success | |
} | |
} | |
object http extends Around { | |
def around[T <% Result](t: =>T) = openHttpSession("test") { | |
t // execute t inside a http session | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment