Created
April 25, 2012 18:19
-
-
Save jfirebaugh/2491871 to your computer and use it in GitHub Desktop.
Auto-restoring sinon fakes with Konacha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require spec_helper | |
Test = | |
fn: -> 'result' | |
it 'auto-resets sinon fakes', -> | |
@stub(Test, 'fn') | |
Test.fn() | |
Test.fn.should.have.been.called | |
it 'has been reset', -> | |
Test.fn().should.equal('result') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Injected by sinon.js | |
Konacha.mochaOptions.globals = [ | |
'XMLHttpRequest' | |
'setTimeout' | |
'setInterval' | |
'clearTimeout' | |
'clearInterval' | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= require support/sinon | |
#= require support/sinon-chai | |
window.chai.use(window.sinonChai) | |
beforeEach -> | |
@sandbox = sinon.sandbox.create | |
injectInto: this | |
properties: ["spy", "stub", "mock", "clock", "server", "requests"], | |
useFakeTimers: true, | |
useFakeServer: true | |
afterEach -> | |
@sandbox.restore() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, thanks for posting your solution.
Btw, since you are using CoffeeScript, which auto-adds
var
, I assume it's safe to just enable ignoreLeaks instead of maintaining aglobals
list.