Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example for using the Outside and AroundOutside traits
/**
* 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