Skip to content

Instantly share code, notes, and snippets.

@armw4
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armw4/9259134 to your computer and use it in GitHub Desktop.
Save armw4/9259134 to your computer and use it in GitHub Desktop.
jasmine_node beforeAll afterAll helper
# 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
@armw4
Copy link
Author

armw4 commented Feb 27, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment