it's not black magic ;)

it's http://sinonjs.org/docs/#sandbox and https://github.com/mozilla-b2g/gaia/blob/master/test_apps/test-agent/common/test/sinon_helper.js ;)