Last active
August 29, 2015 13:56
-
-
Save armw4/9259134 to your computer and use it in GitHub Desktop.
jasmine_node beforeAll afterAll helper
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
# monkey patches jasmine (node) to provide beforeAll and afterAll hooks | |
# | |
# be sure to add this file as a helper as described in my answer on SO: | |
# | |
# http://stackoverflow.com/a/22054113/389103 | |
# | |
# inspired by https://groups.google.com/forum/#!msg/jasmine-js/1LvuiUPunwU/SXPo6PMGSSMJ | |
# | |
# targets jasmine-node@1.13.1 and jasmine@1.3.1 | |
# | |
# https://github.com/mhevery/jasmine-node/blob/abfe06a684c00091b24b4918192920c5534b95c2/lib/jasmine-node/jasmine-1.3.1.js | |
beforeAll = (done) -> | |
# execute your stuff (i.e. datase connection) | |
# assuming you need to execute something asynchronously | |
# hence the done callback. if not, do your synchronous | |
# work and call done, else call done within the callback | |
# of your asynchronous work. | |
# establish connection to database for integration tests | |
# mongoose.connect() | |
done() | |
env = jasmine.getEnv() | |
execute = env.execute | |
env.execute = -> | |
beforeAll -> | |
execute.call env | |
afterAll = (done) -> | |
# execute your stuff (i.e. database disconnect) | |
# assuming you need to execute something asynchronously | |
# hence the done callback. if not, do your synchronous | |
# work and call done, else call done within the callback | |
# of your asynchronous work. | |
# mongoose.disconnect() | |
done() | |
runner = env.currentRunner(); | |
postExecute = runner.finishCallback; | |
runner.finishCallback = -> | |
afterAll -> | |
postExecute.call runner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This guy is for _one_ time setup and teardown. It doesn't take into account multiple subscriptions/actions (iterate over array of callbacks). That was _not_ my intent here. It's a _one_ time thing.