Skip to content

Commit bc4b55a

Browse files
committed
buster example test
1 parent 2f655b1 commit bc4b55a

File tree

5 files changed

+84
-2
lines changed

5 files changed

+84
-2
lines changed

Jakefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var ISTANBUL = './node_modules/.bin/istanbul';
2+
var BUSTER = './node_modules/.bin/buster test';
23
var COVERAGE_OPTS = '--lines 95 --statements 90 --branches 80 --functions 90';
34

45
var print_opts = {printStdout: true, printStderr: true};
@@ -17,13 +18,13 @@ namespace('test', function() {
1718
});
1819

1920
desc('Run tests with test coverage');
20-
task('cover', {async: true}, function(args) {
21+
task('cover', {async: true}, function() {
2122
var command = ISTANBUL + " cover test/run.js";
2223
jake.exec(command, complete, print_opts);
2324
});
2425

2526
desc('Check test coverage');
26-
task('check-coverage', {async: true}, function(args) {
27+
task('check-coverage', {async: true}, function() {
2728
var command = ISTANBUL + " check-coverage " + COVERAGE_OPTS;
2829
jake.exec(command, complete, print_opts);
2930
});
@@ -33,6 +34,12 @@ namespace('test', function() {
3334
var command = "test/run.js -T acceptance --timeout 30000";
3435
jake.exec(command, complete, print_opts);
3536
});
37+
38+
desc('Run sample Buster.js test');
39+
task('buster', {async: true}, function() {
40+
var command = BUSTER;
41+
jake.exec(command, complete, print_opts);
42+
});
3643
});
3744

3845
var JSHINT = './node_modules/jshint/bin/hint --config .jshintrc';

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ BASE = .
33
ISTANBUL = ./node_modules/.bin/istanbul
44
TEST_COMMAND = NODE_ENV=test ./node_modules/.bin/mocha
55
COVERAGE_OPTS = --lines 95 --statements 90 --branches 80 --functions 90
6+
BUSTER = ./node_modules/.bin/buster test
67

78
main: lint test
89

@@ -18,6 +19,9 @@ test: cover check-coverage
1819
test-cov: cover check-coverage
1920
open coverage/lcov-report/index.html
2021

22+
test-buster:
23+
$(BUSTER)
24+
2125
test-acceptance:
2226
test/run.js -T acceptance
2327

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"settings": "0.1.0"
1717
},
1818
"devDependencies": {
19+
"buster": "0.6.3",
1920
"Faker" : "git://github.com/BryanDonovan/Faker.js.git#master",
2021
"jshint": "0.9.0",
2122
"jugglingdb": "0.2.0-2",

test/buster.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var config = module.exports;
2+
3+
config["Buster tests"] = {
4+
environment: "node",
5+
tests: [
6+
"**/buster/**/*unit.js"
7+
]
8+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var buster = require('buster');
2+
buster.spec.expose(); // Make spec functions global
3+
var assert = buster.assert;
4+
5+
var restify = require('restify');
6+
var support = require('../../../support');
7+
var http = support.http;
8+
var User = main.models.User;
9+
10+
var spec = describe("users/controller.js", function () {
11+
var app;
12+
var http_client;
13+
14+
beforeAll(function () {
15+
http_client = http.client();
16+
app = main.app();
17+
app.register('users', {port: http.port});
18+
});
19+
20+
afterAll(function () {
21+
app.close_server();
22+
});
23+
24+
describe("POST /users", function () {
25+
var params;
26+
27+
beforeEach(function () {
28+
params = {username: support.random.string(), password: support.random.string()};
29+
});
30+
31+
it("passes params to User model", function (done) {
32+
this.stub(User, 'create', function (args, cb) {
33+
cb(null, {});
34+
});
35+
36+
http_client.post('/users', params, function (err, result) {
37+
buster.refute(err);
38+
assert(User.create.calledWith(params));
39+
assert(true);
40+
User.create.restore();
41+
done();
42+
});
43+
});
44+
45+
describe("when model returns an error", function () {
46+
it("responds with the error", function (done) {
47+
var fake_err = new restify.InvalidArgumentError('foo');
48+
this.stub(User, 'create', function (args, cb) {
49+
cb(fake_err, {});
50+
});
51+
52+
http_client.post('/users', params, function (err, result) {
53+
assert(User.create.calledWith(params));
54+
assert.equals(result.code, 'InvalidArgument');
55+
assert.equals(result.message, 'foo');
56+
User.create.restore();
57+
done();
58+
});
59+
});
60+
});
61+
});
62+
});

0 commit comments

Comments
 (0)