Created
July 29, 2012 15:53
-
-
Save yangchenyun/3199697 to your computer and use it in GitHub Desktop.
final calculator tests with stub
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
sample = require('../sample') | |
assert = require('assert') | |
sinon = require('sinon') | |
describe "calculator", -> | |
before -> | |
@calculator = sinon.spy sample, 'calculator' | |
@multiple = sinon.spy sample, 'multiple' | |
@addition = sinon.spy sample, 'addition' | |
@minus = sinon.spy sample, 'minus' | |
@divide = sinon.spy sample, 'divide' | |
it "should throw an error if no method is matched", -> | |
try | |
sample.calculator('non-exist-method', 1, 2) | |
catch e | |
sinon.assert.threw(@calculator) | |
it "should call the given method when parameter is valid", -> | |
methods = ['multiple', 'addition', 'minus', 'divide'] | |
for method in methods | |
sample.calculator(method, 1, 2) | |
sinon.assert.calledOnce(@[method]) | |
sinon.assert.calledWithExactly(@[method], [1, 2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment