Skip to content

Commit

Permalink
[test] Add useful mocks
Browse files Browse the repository at this point in the history
This adds basic mocks for:

  * `ChildProcess`
  * `Stream`
  * `forever.Monitor`
  • Loading branch information
mmalecki committed Dec 9, 2011
1 parent ed75bd4 commit cdb355f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/helpers/mocks/child-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var util = require('util'),
EventEmitter2 = require('eventemitter2').EventEmitter2,
StreamMock = require('./stream').StreamMock;

var ChildProcessMock = exports.ChildProcessMock = function () {
EventEmitter2.call(this);

this.stdout = new StreamMock();
this.stderr = new StreamMock();
};
util.inherits(ChildProcessMock, EventEmitter2);

11 changes: 11 additions & 0 deletions test/helpers/mocks/monitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var util = require('util'),
broadway = require('broadway'),
ChildProcessMock = require('./child-process').ChildProcessMock;

var MonitorMock = exports.MonitorMock = function (options) {
broadway.App.call(this, options);

this.child = new ChildProcessMock();
};
util.inherits(MonitorMock, broadway.App);

19 changes: 19 additions & 0 deletions test/helpers/mocks/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var util = require('util'),
EventEmitter2 = require('eventemitter2').EventEmitter2;

var StreamMock = exports.StreamMock = function () {
EventEmitter2.call(this);

this.contents = [];
this.closed = false;
};
util.inherits(StreamMock, EventEmitter2);

StreamMock.prototype.write = function (data) {
this.contents.push(data);
};

StreamMock.prototype.close = function () {
this.closed = true;
};

0 comments on commit cdb355f

Please sign in to comment.