title: Stubbing a Mongoose model using Sinon
body: <p>I am trying to stub the mongoose dependency used in this object:</p>
  
  <pre><code>var Page = function(db) {
  
      var mongoose = db || require('mongoose');
  
      if(!this instanceof Page) {
          return new Page(db);
      }
  
      function save(params) {
          var PageSchema = mongoose.model('Page');
  
          var pageModel = new PageSchema({
              ...
          });
  
          pageModel.save();
      }
  
      Page.prototype.save = save;
  }
  
  module.exports = Page;
  </code></pre>
  
  <p>Using the answer for <a href="https://stackoverflow.com/questions/11318972/stubbing-a-mongoose-model-with-sinon">this question</a>, I've tried doing this:</p>
  
  <pre><code>mongoose = require 'mongoose'
  sinon.stub mongoose.Model, 'save'
  </code></pre>
  
  <p>But I got the error: </p>
  
  <p><strong>TypeError: Attempted to wrap undefined property save as function</strong></p>
  
  <p>I also tried this:</p>
  
  <pre><code>sinon.stub PageSchema.prototype, 'save'
  </code></pre>
  
  <p>And then I got the error:</p>
  
  <p><strong>TypeError: Should wrap property of object</strong></p>
  
  <p>Can anyone help with this? What am I doing wrong?</p>