Created
March 16, 2012 14:42
-
-
Save laribee/2050358 to your computer and use it in GitHub Desktop.
Sinon Mocks vs. Stubs
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
sinon = require('sinon') | |
should = require('chai').should() | |
class Bar | |
print: (message) -> | |
message | |
class Foo | |
doSomething: (bar)-> | |
console.log(bar.print('hello')) | |
describe "mocks vs. stubs with sinon.js", -> | |
it "you could use a mock", -> | |
bar = new Bar | |
mock = sinon.mock(bar).expects("print").once().returns('howdy') | |
new Foo().doSomething(bar) | |
mock.verify() # verify what?! oh... line 19. COMEFROM, lol | |
it "but why not use a stub", -> | |
bar = new Bar | |
barPrintStub = sinon.stub(bar, "print").returns('aloha') | |
new Foo().doSomething(bar) | |
barPrintStub.called.should.be.true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment