title: sinon: stub a function that is not attached to an object
body: <p>I'm trying to use <a href="http://sinonjs.org/" rel="nofollow noreferrer">sinon</a> to stub some functionality of <a href="https://github.com/steveukx/git-js" rel="nofollow noreferrer">simplegit</a>.  The problem is that simplegit behaves in a very annoying fashion: <code>require('simple-git')</code> returns a function, which you need to call in order to get the object that is actually useful.  The result of this is that you get a different object each time, making stubbing with sinon (the normal way) impossible.</p>
  
  <p>So I need to stub the function that gets returned by <code>require('sinon')</code>, so that I can override the bahavior of simplegit in its totality.  Basically, I want to do <em>something</em> like this (but this doesn't work):</p>
  
  <pre><code>const sinon = require('sinon')
  var simplegit = require('simple-git')
  
  //I'm well aware that this isn't valid
  sinon.stub(simplegit).callsFake(function() {
    return {
      silent: function() {return this},
      pull: function() {console.log('pulled repo'); return this},
      clone: function() {console.log('cloned repo'); return this}
    }
  }
  
  external_function() //this function calls simplegit
  </code></pre>
  
  <p>This would result in an object that has the functions that I need, but does nothing.  It avoids the actual simplegit implementation altogether.</p>
  
  <p>Is this possible to do?</p>