Created
December 9, 2011 14:44
-
-
Save ericbock/1451789 to your computer and use it in GitHub Desktop.
using sinon to stub a method
This file contains hidden or 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 '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