Skip to content

Commit

Permalink
Added additional tests for AbstractCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kragenbrink authored and nivthefox committed Aug 16, 2015
1 parent 5f0fae2 commit dd31166
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
8 changes: 5 additions & 3 deletions jasmine/commands/AbstractCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class AbstractCommand {
constructor (caller, switches, args) {
if (this.constructor === AbstractCommand) {
throw new TypeError("Cannot construct Abstract instances directly.");
}

this.caller = caller;
if (switches) this.switches = switches.split('/');
if (args) this.args = args.split(' ');
Expand All @@ -10,9 +14,7 @@ class AbstractCommand {
static get command () { throw new Error('Command must define syntax'); }
static get aliases () { return []; }

execute () {
throw new Error('Command must implement execute method.');
}
execute () {}
}

module.exports = AbstractCommand;
10 changes: 1 addition & 9 deletions jasmine/test/Session.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ const net = require('net');
const proxyquire = require('proxyquire');
const queue = require('jasmine/Queue').instance;

const AbstractCommand = require('jasmine/commands/AbstractCommand');
const TestCommand = require('jasmine/test/mock/commands/TestCommand');
const Mitm = require('mitm');

class TestCommand extends AbstractCommand {
static get command () { return 'test'; }
static get aliases () { return ['foo']; }
execute () {
process.emit('executed TestCommand');
}
}

describe("jasmine.Session", function () {
let mitm, serverSocket, clientSocket;
const Session = proxyquire('jasmine/Session', {});
Expand Down
29 changes: 29 additions & 0 deletions jasmine/test/commands/AbstractCommand.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const assert = require('assert');
const proxyquire = require('proxyquire');
const TestCommand = require('jasmine/test/mock/commands/TestCommand');

describe("jasmine.commands.AbstractCommand", function () {
const AbstractCommand = proxyquire('jasmine/commands/AbstractCommand', {});

it('should not allow you to instantiate it directly', function () {
assert.throws(function () {
new AbstractCommand;
}, TypeError);
});

it('should allow extending classes to be instantiated', function () {
let instance;
let caller = {};
let switches = 'foo/bar/baz';
let args = 'foo bar baz';
assert.doesNotThrow(function () {
instance = new TestCommand(caller, switches, args);
});

assert.strictEqual(instance.caller, caller);
assert.deepEqual(instance.switches, switches.split('/'));
assert.deepEqual(instance.args, args.split(' '));
});
});
13 changes: 13 additions & 0 deletions jasmine/test/mock/commands/TestCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const AbstractCommand = require('jasmine/commands/AbstractCommand');

class TestCommand extends AbstractCommand {
static get command () { return 'test'; }
static get aliases () { return ['foo']; }
execute () {
process.emit('executed TestCommand');
}
}

module.exports = TestCommand;

0 comments on commit dd31166

Please sign in to comment.