title: Spy, Stub or Mock? Or None of the Above?
body: <p>I'm using Mocha to test a Node.js API. I need to test a route that checks whether an update is available. The route accepts a version number of what's currently installed and compares it with an available version retrieved via an HTTP request.</p>
  
  <p>To get the latest version available, a model method is called. <code>Client.availableVersion()</code> makes the HTTP request, does some simple manipulation and passes the available version to a callback function. Fairly straightforward stuff, but now I want to test my <code>update()</code> route and I need to be able to control what is returned by <code>Client.availableVersion()</code>.</p>
  
  <p>Having read the Mocha docs and the <a href="http://sinonjs.org/" rel="nofollow">Sinon</a> docs I was referred to...I'm stuck. It sounds like Sinon will handle what I need, but the implementation has me a little confused.</p>
  
  <p>Here's a snippet from my routes method:</p>
  
  <pre><code>update: function( req, res, next ) {
    var installedVersion = req.params.version;
  
    client.availableVersion( function( err, availableVersion ) {
      if( !err ) {
        if( parseInt( installedVersion, 10 ) &lt; parseInt( availableVersion, 10 ) ) {
          // SEND UPDATE AVAILABLE RESPONSE
        }
  
        // SEND NO UPDATE AVAILABLE RESPONSE
      }
      else {
        res.send( 500, err );
      }
    })
  }
  </code></pre>
  
  <p>Any nudge in the right direction would be appreciated.</p>