Skip to content

Instantly share code, notes, and snippets.

@ericbock
Created December 9, 2011 14:44
Show Gist options
  • Save ericbock/1451789 to your computer and use it in GitHub Desktop.
Save ericbock/1451789 to your computer and use it in GitHub Desktop.
using sinon to stub a method
sinon = require 'sinon'
should = require 'should'
class LaserGun
fireAt: (alien) ->
console.log "ZAP"
class BuckRogers
constructor: (@laserGun) ->
attack: (alien) ->
@laserGun.fireAt(alien)
describe "Buck Rogers", ->
# sinon is designed around just stubbing a particular method
it "should fire his laser at the alien when he attacks", ->
alien = {}
laser = new LaserGun
stub = sinon.stub laser, "fireAt"
buck = new BuckRogers(laser)
buck.attack(alien)
stub.calledWith(alien).should.be.true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment