cjohansen/Sinon.JS — pull request #531 by mwise (2014-08-01 22:23:35+00:00)
Title: Add sinon.pollute() and sinon.pollute.purify()

This PR adds sinon.pollute() to add Object.prototype.stub and Object.prototype.spy. We are using Sinon.JS in a Ruby on Rails application, and this change allows you to use sinon with an RSpec-style syntax.

After calling `sinon.pollute()`, you can do things like `someObject.stub("someMethod")` and `someObject.spy("someMethod")` instead of `sinon.stub(someObject, "someMethod")` and `sinon.spy(someObject, "someMethod")`. You can also pass an object to stub a method and its return value in one statement, e.g. `someObject.stub({ someMethod: "some value" })`. In this example, calling `someObject.someMethod()` will be a stub that returns `"some value"`.

Calling `sinon.pollute.purify()` will remove Object.prototype.stub and Object.prototype.spy.

I'm not sure if the feature is desirable, but it is a really nice change for folks who are using Sinon.JS in a project that also contains RSpec tests. It cuts down on the context-switching that is required when doing a full-stack feature that includes Ruby and JavaScript specs.

Please let me know if there is anything that needs changing in this PR, or if you would prefer me to roll this as a plugin or something similar.

Cheers,

Mark