Skip to content

Instantly share code, notes, and snippets.

@laribee
Created March 16, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laribee/2050358 to your computer and use it in GitHub Desktop.
Save laribee/2050358 to your computer and use it in GitHub Desktop.
Sinon Mocks vs. Stubs
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