cjohansen/Sinon.JS — pull request #364 by pimterry (2013-12-15 21:53:05+00:00)
Title: Set returnValues correctly when the spied function is called as a constructor

This patch changes Sinon to fix #351. Now, when working out the return value of a spied method, we check whether it's being called with new, and whether the method didn't explicitly return an object value, and if so we update the return value to be the constructed object instead.

I'm happy personally that all of this works and with the tests themselves, but I feel like the `thisCall = ...` bit is slightly messy. I've not played with Sinon's internals before now, and I can't find a nicer way to do this, but if you do have any suggestions I'd be very happy to hear them!