Created
April 6, 2011 14:58
-
-
Save etorreborre/905789 to your computer and use it in GitHub Desktop.
An example for using the Outside and AroundOutside traits
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
/** | |
* This object provides a http request to be passed to examples | |
*/ | |
object http extends Outside[HttpReq] { | |
// prepare a valid HttpRequest | |
def outside: HttpReq = createRequest | |
} | |
/** | |
* It is used like that, with the apply method provided by the Outside trait. | |
* The apply method takes a function with one parameter returning a Result | |
*/ | |
"this is a first example where the code executes uses a http request" ! http((request: HttpReq) => success) | |
"and another one" ! http((request: HttpReq) => success) | |
/** | |
* This is not real magic but the apply method takes care of anything that could go wrong during the creation of the | |
* "outside" object and will return an Error if an Exception is raised or a Skipped message | |
* if a Skipped exception was thrown. Then the rest of the code is not executed | |
*/ | |
/** | |
* There is also a combining trait to have both an object being passed to each example but also code executed around | |
* each example: | |
*/ | |
object http extends AroundOutside[HttpReq] { | |
// prepare the global environment | |
// each example will be executed in that environment | |
def around[R <% Result](r: =>R): Result = { | |
createNewDatabase | |
// execute the code inside a databaseSession | |
inDatabaseSession { r } | |
} | |
// prepare a valid HttpRequest | |
def outside: HttpReq = createRequest | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment