var _ = require('lodash'),
    sinon = require('sinon'),
    expect = require('chai').expect,
    Collection = require('postman-collection').Collection,
    Runner = require('../../index.js').Runner,

    runtime;

runtime = function (spec, done) {
    _.isString(spec) && (spec = require('./' + spec));

    var runner = new Runner(_.merge({}, spec.options)),
        callbacks = {};

    // add a spy for each callback
    _.forEach(_.keys(Runner.Run.triggers), function (eventName) {
        callbacks[eventName] = sinon.spy();
    });

    // the final done callback needs special attention
    callbacks.done = sinon.spy(function () {
        done(null, callbacks, spec);
    });

    // eslint-disable-next-line handle-callback-err
    runner.run(new Collection(spec.collection), _.omit(spec, ['collection', 'options']), function (err, run) {
        run.start(callbacks);
    });
};

before(function () {
    global.sinon = sinon; // expose global for ease of use
    global.expect = expect; // expose global
    this.run = runtime;
});

after(function () {
    delete global.sinon;
    delete global.expect;
});

@@ -48,16 +48,32 @@
 'sinon')
+.createSandbox()
 ,%0A    ex
@@ -254,24 +254,176 @@
 ec, done) %7B%0A
+    // reset the internal state of all spies created in the previous run%0A    // Refer: https://sinonjs.org/releases/latest/sandbox/%0A    sinon.reset();%0A%0A
     _.isStri
@@ -1077,67 +1077,8 @@
 ) %7B%0A
-    global.sinon = sinon; // expose global for ease of use%0A
     
@@ -1171,33 +1171,8 @@
 ) %7B%0A
-    delete global.sinon;%0A
     

use sinon sandbox for spies