cjohansen/Sinon.JS — pull request #352 by jmreidy (2013-11-19 18:22:27+00:00)
Title: Adding `stub.safe()` functionality

Sinon's stubs already protect against API drift by checking an object
for the existance of a property name before stubbing the property. (If a
target object no longer implements a property, existing tests which
stub that property will fail). But there's currently no protection
against an API decreasing its number of accepted arguments. For example,
image a stub that expects an interface will be called with `foo, bar`;
if the target interface's signature changes from accepting `foo, bar` to
accepting an options hash, the test will continue being green.

Because it's sometimes desirable in JavaScript to allow more arguments
than a function signature expects, there can't be a universal check of
target function arity. Instead, this PR adds a new `safe` method to
stubs, which turns an arity check on. If a target function's signature
changes to accept less arguments than a test with `safe` supplies, the
test will turn red, further protecting against API drift.