Created
October 4, 2013 02:28
-
-
Save ishiduca/6820091 to your computer and use it in GitHub Desktop.
TestDouble の TestStub と TestSpy
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
| // 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