I may have gotten something wrong, but the last assertion in the test below fails.
Put the code below inside the default unit test created when generating a new application to run it, and make sure you include qx.dev.unit.MMock. Can't provide a playground link because either I'm too stupid to do it or the playground doesn't load the dev/test classes, therefore MMock isn't available there. // that's just a pretext for a recursive function, could be anything. flatten: function(binaryTreeNode, list) { if (!binaryTreeNode) return "noop"; if (binaryTreeNode.left || binaryTreeNode.right) { this.flatten(binaryTreeNode.left, list); this.flatten(binaryTreeNode.right, list); return "flatten"; } else { list.push(binaryTreeNode); return "push"; } }, "test: 02. sinon/MMock doesn't properly record return values for recursive calls": function() { var binaryTreeNode = { left: "left", right: "right" } var spy = this.spy(this, "flatten"); var list = [] this.flatten(binaryTreeNode, list); var returnValuesTheRightWay = [ spy.getCall(0).returnValue, spy.getCall(1).returnValue, spy.getCall(2).returnValue ]; this.assertEquals(binaryTreeNode, spy.getCall(0).args[0]); // returned "flatten" this.assertEquals(binaryTreeNode.left, spy.getCall(1).args[0]); // returned "push" this.assertEquals(binaryTreeNode.right, spy.getCall(2).args[0]); // returned "push" this.assertArrayEquals(["flatten", "push", "push"], spy.returnValues, "Return values as returned by spy.returnValues are wrong."); this.getSandbox().restore(); } Return values are recorded in the order they are returned, not in the order the calls are performed. As a consequence, in case of recursive calls, the return values of the innermost calls are recorded first, even if these calls happen last. When you then call spy.getCall(0).returnValue, you get the result of the last call, instead of the first. After having looked into the sinon code, this should be easily fixable by changing sinon's invoke() to treat the return values as a map, instead of a linear array, and put return values into it by index, instead of using push(). Since the bug is in sinon, I'd rather not file a qooxdoo bug. I filed an issue on github for sinon instead - https://github.com/cjohansen/Sinon.JS/issues/760. But maybe the qooxdoo maintainers want to address this before sinon fixes it. Simple rules (...) lead to complex behavior. Complex rules (...) lead to stupid behavior. (Getting Real, 37Signals - now Basecamp)
------------------------------------------------------------------------------
_______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel