Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created October 4, 2013 02:28
Show Gist options
  • Select an option

  • Save ishiduca/6820091 to your computer and use it in GitHub Desktop.

Select an option

Save ishiduca/6820091 to your computer and use it in GitHub Desktop.
TestDouble の TestStub と TestSpy
// see http://goyoki.hatenablog.com/entry/20120301/1330608789
var q = require('qunitjs')
;(function () {
var qTap = require('qunit-tap')
qTap(q, require('util').puts, {showSourceOnFailure: false})
q.init()
q.config.updateRate = 0
q.assert.is = q.assert.strictEqual
})()
q.module('stub: 関節入力値を操作する', {
setup: function () {
this.stub = function () { return this.v }.bind(this)
}
, teardown: function () {
this.v = null
}
})
q.test('use stub', function (t) {
var subt = function subt (input, except) {
this.v = input
t.is(except, this.stub())
}.bind(this)
subt(100, 100)
subt(-1, -1)
})
q.module('spy: 間接出力値を操作する', {
setup: function () {
this.spy = function (input) { this.output = input }.bind(this)
}
, teardown: function () {
this.output = null
}
})
q.test('use spy', function (t) {
var subt = function subt (input, except) {
this.spy(input)
t.is(except, this.output)
}.bind(this)
subt(100, 100)
subt(-1, -1)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment