 
   # mock sentry dsn with random uuid as public_key and secret_key
   dsn = 'https://1234567890abcdef:fedcba0987654321@app.getsentry.com/12345'
+
+  beforeEach -> @scope = null
+  afterEach -> @scope?.done()
 
   it 'setup sentry client from specified DSN correctly', ->
     _sentry = new Sentry dsn

      .reply(200, {"id": "c3115249083246efa839cfac2abbdefb"}) # mock sentry response with a random uuid

    @sentry.message 'message', '/path/to/logger'
    scope.done()

  it 'emit logged event when successfully made an api call', (done) ->
    scope = nock('https://app.getsentry.com')
      .filteringRequestBody(/.*/, '*')
      .post("/api/#{sentry_settings.project_id}/store/", '*')
      .reply(200, 'OK')

    @sentry.on 'logged', ->
      scope.done()
      done()

    @sentry.error new Error('wtf?'), "Unknown Error", "/"

  it 'emit error event when the api call returned an error', (done) ->
    scope = nock('https://app.getsentry.com')
      .filteringRequestBody(/.*/, '*')
      .post("/api/#{sentry_settings.project_id}/store/", '*')
      .reply(500, 'Oops!', {'x-sentry-error': 'Oops!'})

    @sentry.once 'error', (err) ->
      scope.done()
      done()

    @sentry.message "hey!", "/"

  it 'one time listener should work correctly', (done) ->
    _sentry = new Sentry(sentry_settings)

    scope = nock('https://app.getsentry.com')
      .filteringRequestBody(/.*/, '*')
      .post("/api/#{sentry_settings.project_id}/store/", '*')
      .reply(500, 'Oops!', {'x-sentry-error': 'Oops!'})

    _sentry.once 'error', ->
      scope.done()
      done()

    _sentry.message "hey!", "/"


    assert.equal _sentry.disable_message, "Credentials you passed in aren't complete."

  it 'warns if passed an error that isnt an instance of Error', ->
    @scope = nock('https://app.getsentry.com')
      .matchHeader('X-Sentry-Auth'
      , "Sentry sentry_version=4, sentry_key=#{sentry_settings.key}, sentry_secret=#{sentry_settings.secret}, sentry_client=sentry-node")
      .filteringRequestBody (path) ->
