Working gateway

Change-Id: I8ca690fe9d1b7f8e20b438df1ddd48d6b2f99326
diff --git a/spec/spec_helper.js b/spec/spec_helper.js
new file mode 100644
index 0000000..abedb29
--- /dev/null
+++ b/spec/spec_helper.js
@@ -0,0 +1,42 @@
+(function () {
+  'use strict';
+  
+  const sinon = require('sinon');
+
+  let stubCache = {};
+
+  exports.makeStub = (name, target, method, cb) => {
+    
+    let methodStub, prototypeStub;
+
+    function SuperAgentStub(end) {
+      this.end = end;
+      this.set = sinon.stub().returns(this);
+      this.send = sinon.stub().returns(this);
+      return this;
+    }
+
+    beforeEach(() => {
+      methodStub = sinon.stub(target, method);
+
+      prototypeStub = new SuperAgentStub(cb);
+
+      methodStub.returns(prototypeStub);
+
+      // cache stub (for use in tests)
+      stubCache[name] = {
+        set: prototypeStub.set,
+        send: prototypeStub.send
+      };
+      stubCache[name][method] = methodStub
+    });
+
+    afterEach(() => {
+      target[method].restore();
+    });
+    
+  };
+
+  exports.getStub = name => stubCache[name];
+
+})();
\ No newline at end of file