cjohansen/Sinon.JS — pull request #223 by telaviv (2012-12-25 02:27:31+00:00)
Title: Added spec functionality.

Right now when writing sinon tests a very common pattern is to do something like this:

```javascript
var obj = {'foo': function() {}};
var spy = sinon.spy(obj, 'foo');
obj.foo(3);
sinon.assertCalledWith(spy, e);
```

The problem comes when you change the definition of the class of "obj." When you get rid of the "foo" method, or simply rename it, your unit tests pass, but your code is totally broken! This starts to become an increasingly big issue in large codebases because you can no longer depend on your tests to fail when regressions happen.

Here is the feature I've added:

```javascript
var spec = sinon.spec(ObjConstructor);
spec.foo(3); // this throws an exception if foo isn't defined.
sinon.assertCalledWith(spec.foo, 3); // all spec methods are just spies.
```

The idea was mostly inspired by the autospec feature of python's mock library, and mockitos "mock" feature.