title: Mocha test suite errorring out when attempting to connect to API
body: <p>I'm running my test suite using <code>mocha</code>, via <code>gulp-jsx-coverage</code> and <code>gulp-mocha</code>. All my tests run and pass/fail as expected. However, some of my modules being tested make HTTP requests to my API via the <code>superagent</code> library. </p>
  
  <p>When in development, I'm also running my API at <code>localhost:3000</code> alongside my client-side app, and so that is the URL my client-side tests are attempting to access. When testing, though, the API is usually not running. This results in the following error any time a request gets through:</p>
  
  <pre><code>Error in plugin 'gulp-mocha'
  Message:
      connect ECONNREFUSED
  Details:
      code: ECONNREFUSED
      errno: ECONNREFUSED
      syscall: connect
      domainEmitter: [object Object]
      domain: [object Object]
      domainThrown: false
  Stack:
  Error: connect ECONNREFUSED
      at exports._errnoException (util.js:746:11)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:983:19)
  </code></pre>
  
  <p>I've tried stubbing all of the methods on the <code>superagent</code> (aliased as <code>request</code>) library in a global helper, like so:</p>
  
  <pre><code>function httpStub() {
    return {
      withCredentials: () =&gt; {
        return { end: () =&gt; {} };
      }
    };
  };
  
  beforeEach(function() {
    global.sandbox = sinon.sandbox.create();
  
    global.getStub = global.sandbox.stub(request, 'get', httpStub);
    global.putStub = global.sandbox.stub(request, 'put', httpStub);
    global.patchStub = global.sandbox.stub(request, 'patch', httpStub);
    global.postStub = global.sandbox.stub(request, 'post', httpStub);
    global.delStub = global.sandbox.stub(request, 'del', httpStub);
  });
  
  afterEach(function() {
    global.sandbox.restore();
  });
  </code></pre>
  
  <p>But for some reason, when some tests are encountered the methods aren't stubbed and so I reach the <code>ECONNREFUSED</code> error. I've triple checked, and no where am I restoring the sandbox or any stubs.</p>
  
  <p>Is there either a way to fix the problem I'm running into, or a cleaner solution for this overall?</p>