title: Creating a fake object.method() "from scratch" in sinon?
body: <h3>tl;dr</h3>
  
  <p>How do you create an object.method() "from scratch" in sinon?  </p>
  
  <h3>the context</h3>
  
  <p>For example, I have a family of <code>Parser</code> classes where each implements a <code>#parse(text)</code> method and returns a <code>ParseTree</code> object or returns <code>null</code>.  </p>
  
  <p>I am doing unit testing where I'm <em>not</em> testing <code>Parser</code> objects themselves (they are tested elsewhere) but I need an testable object that responds to <code>#parse()</code>.   I could instantiate and stub a real Parser, but that drags needless code into this part of the test.  </p>
  
  <h3>the question</h3>
  
  <p>I'm pretty sure this is easy using sinon's spy(), stub() and/or mock() api's, so: how do I create a testable object that:</p>
  
  <ul>
  <li>responds to the parse() method</li>
  <li>verifies that it is called once</li>
  <li>returns an arbitrary object that I specify?</li>
  </ul>
  
  <h3>what I've tried</h3>
  
  <p>The following contrived example fails in the call to <code>sinon.stub()</code> because a <code>sinon.spy()</code> object cannot be stubbed with a <code>parse</code> method.  (This example should also verify that <code>fake_parser.parse()</code> was called once with <code>test_text</code>, but it doesn't):</p>
  
  <pre><code>var test_text = 'any text'
  var fake_parse_tree = sinon.spy()
  var fake_parser = sinon.stub(sinon.spy(), 'parse').returns(fake_parse_tree)
  
  expect(fake_parser.parse(test_text)).to.equal(fake_parse_tree)
  </code></pre>