Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Commit

Permalink
Add unit tests to CLI module.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Nov 19, 2014
1 parent 3c01bb4 commit b8a5151
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/baker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var Baker = require('../lib/baker');
var buster = require('buster-node');
var referee = require('referee');
var webshot = require('webshot');
var assert = referee.assert;

buster.testCase('breaker - _iterPostsByTags', {
setUp: function () {
this.mockConsole = this.mock(console);
},
'should pass error to callback when error occurred while retrieving posts': function (done) {
this.mockConsole.expects('log').once().withExactArgs('* tag: %s', 'tag1'.cyan);
var mockEggtart = {
posts: function () {
return {
recent: function (opts, cb) {
cb(new Error('some error'));
}
};
}
};
var baker = new Baker(mockEggtart);
baker._iterPostsByTags(['tag1', 'tag2'], null, function (err, result) {
assert.equals(err.message, 'some error');
done();
});
},
'should log message when no posts found': function (done) {
this.mockConsole.expects('log').once().withExactArgs('* tag: %s', 'tag1'.cyan);
this.mockConsole.expects('log').once().withExactArgs('* tag: %s', 'tag2'.cyan);
this.mockConsole.expects('log').twice().withExactArgs('%s - %s', 'warn'.yellow, 'No bookmark found');
var mockEggtart = {
posts: function () {
return {
recent: function (opts, cb) {
cb(null, {});
}
};
}
};
var baker = new Baker(mockEggtart);
baker._iterPostsByTags(['tag1', 'tag2'], null, function (err, result) {
assert.equals(err, undefined);
done();
});
}
});
76 changes: 76 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var bag = require('bagofcli');
var Baker = require('../lib/baker');
var buster = require('buster-node');
var cli = require('../lib/cli');
var referee = require('referee');
var assert = referee.assert;

buster.testCase('cli - exec', {
'should contain commands with actions': function (done) {
var mockCommand = function (base, actions) {
assert.defined(base);
assert.defined(actions.commands.delete.action);
assert.defined(actions.commands.screenshot.action);
done();
};
this.mock({});
this.stub(bag, 'command', mockCommand);
cli.exec();
}
});

buster.testCase('cli - delete', {
setUp: function () {
this.mock({});
},
'should contain delete command and delegate to baker delete when exec is called': function (done) {
this.stub(bag, 'command', function (base, actions) {
actions.commands.delete.action({ tags: 'tag1,tag2', parent: {} });
});
this.stub(Baker.prototype, 'delete', function (tags, cb) {
assert.equals(tags, ['tag1', 'tag2']);
assert.equals(typeof cb, 'function');
done();
});
cli.exec();
},
'should pass empty array when tags arg is not provided': function (done) {
this.stub(bag, 'command', function (base, actions) {
actions.commands.delete.action({ parent: {} });
});
this.stub(Baker.prototype, 'delete', function (tags, cb) {
assert.equals(tags, []);
assert.equals(typeof cb, 'function');
done();
});
cli.exec();
}
});

buster.testCase('cli - screenshot', {
setUp: function () {
this.mock({});
},
'should contain screenshot command and delegate to baker screenshot when exec is called': function (done) {
this.stub(bag, 'command', function (base, actions) {
actions.commands.screenshot.action({ tags: 'tag1,tag2', parent: { userPass: 'someusername:somepassword' } });
});
this.stub(Baker.prototype, 'screenshot', function (tags, cb) {
assert.equals(tags, ['tag1', 'tag2']);
assert.equals(typeof cb, 'function');
done();
});
cli.exec();
},
'should pass empty array when tags arg is not provided': function (done) {
this.stub(bag, 'command', function (base, actions) {
actions.commands.screenshot.action({ parent: { userPass: 'someusername:somepassword' } });
});
this.stub(Baker.prototype, 'screenshot', function (tags, cb) {
assert.equals(tags, []);
assert.equals(typeof cb, 'function');
done();
});
cli.exec();
}
});

0 comments on commit b8a5151

Please sign in to comment.