Skip to content

Commit

Permalink
* Minor fix for tests
Browse files Browse the repository at this point in the history
* Improved test mocks somewhat, but they still need some attention
  • Loading branch information
TheModFather committed Aug 31, 2013
1 parent 9078fa1 commit 7e2e5eb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -21,6 +21,10 @@ _(Coming soon)_
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

## Release History
### 0.2.1
* Minor fix for tests
* Improved test mocks somewhat, but they still need some attention

### 0.2.0
* Major rewrite of the routing engine to better suit a multitude of custom requesti methods
* Removed Mammock.Endpoint and Mammock.Server, moving main constructor to the initial mammock instance
Expand Down
2 changes: 0 additions & 2 deletions lib/mammock.js
Expand Up @@ -122,7 +122,6 @@ Mammock.prototype.start = function () {
_this.info("Received content type: " + request.headers['content-type']);
}


if (!blacklisted && !missing && !invalidContent) {
_this.info("Request being handled...");
_this.info("Loading endpoint from " + require.resolve(path.join(_this.options.root, route)));
Expand Down Expand Up @@ -191,7 +190,6 @@ Mammock.prototype.start = function () {
});
response.end();
}

});

_this._internals.server.listen(_this.options.port);
Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "mammock",
"description": "Mammock is a node.js service mocking framework designed to be quick and easy, allowing developers to fill the \"missing gaps\" in services during development.",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/earmbrust/mammock",
"author": {
"name": "Elden Armbrust",
Expand Down Expand Up @@ -44,6 +44,7 @@
"winston": "~0.7.2",
"node.extend": "~1.0.8",
"dateformat": "~1.0.6-1.2.3",
"proxyquire": "~0.5.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-uglify": "~0.2.2",
Expand All @@ -52,5 +53,5 @@
"grunt-contrib-clean": "~0.5.0",
"grunt": "~0.4.1"
},
"keywords": []
"keywords": ["mock", "stub", "static", "data", "restful", "rest", "json", "server", "fake"]
}
62 changes: 55 additions & 7 deletions test/mammock_test.js
@@ -1,7 +1,6 @@
'use strict';

var Mammock = require('../lib/mammock.js');

var proxyquire = require('proxyquire');
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
Expand All @@ -22,17 +21,66 @@ var Mammock = require('../lib/mammock.js');
test.ifError(value)
*/


var winstonMock = {
Logger: function () {
return {
info: function () { },
warn: function () { },
error: function () { },
extend: function (object) {
object.info = this.info;
object.warn = this.warn;
object.error = this.error;
}
};
}
};

var httpRequest = {
url: "/",
headers: {
"content-type": "application/json"
}
};

var httpResponse = {
writeHeader: function () { },
end: function () { }
};

var httpMock = {
createServer: function () {
return {
on: this.on,
listen: function () { }
};
},
on: function (event, fn) { fn(httpRequest, httpResponse); },
sendRequest: function (fn) {
this.on("request", fn);
}
};

exports['Server'] = {
setUp: function(done) {
// setup here
done();
},
'no args': function(test) {
test.expect(2);
// tests here
var server = new Mammock({});
test.expect(4);
var Mammock = proxyquire('../lib/mammock.js', { 'winston': winstonMock, 'http': httpMock });
var server = new Mammock();
test.equal(typeof server, 'object', 'should be an object type.');
test.ok(server instanceof Mammock);
test.done();

server.start();
test.ok(server.options && typeof server.options !== 'undefined', 'should instantiate with options');

httpMock.sendRequest(function () {
test.ok(server, "server responds to requests");
});
setTimeout(function () {
test.done();
}, 1000);
},
};

0 comments on commit 7e2e5eb

Please sign in to comment.