Skip to content

Commit

Permalink
[Tests] Harmonized tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil1337 committed Oct 19, 2013
1 parent 3fffbc1 commit cf79bbf
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 279 deletions.
4 changes: 2 additions & 2 deletions tests/greppy/lib/app/worker/appTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var root = path.resolve(__dirname + '/../../../../../');
var express = require('express');
var App = require(root + '/lib/app/worker/app');

describe('app', function() {
describe('App', function() {

var exApp = null;
var app = null;
Expand All @@ -25,7 +25,7 @@ describe('app', function() {
debug: function(s) {
}
};

// mockup of greppy global
greppy = {
config: {
Expand Down
67 changes: 36 additions & 31 deletions tests/greppy/lib/app/worker/contextTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,59 @@ var path = require('path');
var root = path.resolve(__dirname + '/../../../../../');
var express = require('express');
var Context = require(root + '/lib/app/worker/context');
var ct = null;

describe('Context', function() {

describe('context', function() {

var context = null;

it('should have a property name which is based on the provided constructor-parameter', function() {

var param = 'i/am/some/path/to/a/file.js';
context = new Context(param);
context.name.should.equal('file');

ct = new Context(param);

ct.name.should.equal('file');
});

it('should have a property description which should be a string', function() {
context = new Context();

context.description.should.be.a('string');

ct = new Context();

ct.description.should.be.a('string');
});

it('should have a property backends which should be an empty object', function() {
context = new Context();

context.backends.should.eql({});

ct = new Context();

ct.backends.should.eql({});
});

it('should have a property modules which should be an empty array', function() {
context = new Context();

context.modules.should.eql([]);

ct = new Context();

ct.modules.should.eql([]);
});

it('should have a property controllers which should be an empty object', function() {
context = new Context();

context.controllers.should.eql({});

ct = new Context();

ct.controllers.should.eql({});
});

it('should have a property routes which should be an empty object', function() {
context = new Context();

context.modules.should.eql({});

ct = new Context();

ct.modules.should.eql({});
});

it('should have a method configure which calls a given callback', function(done) {
context = new Context();

context.configure(null, null, function() {
ct = new Context();

ct.configure(null, null, function() {
done();
});
});
Expand Down
12 changes: 5 additions & 7 deletions tests/greppy/lib/app/workerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,34 @@ var should = require('should');
var path = require('path');
var root = path.resolve(__dirname + '/../../../../');
var Worker = require(root + '/lib/app/worker');
var wr = null;

// currently not working correctly
describe.skip('worker', function() {
describe.skip('Worker', function() {

var cwdBak;
var cwdBak = process.cwd();

before(function() {

cwdBak = process.cwd();
process.chdir('/tmp/greppy/project/');
greppy = require(root + '/lib/greppy');
});

after(function() {

delete greppy;
process.chdir(cwdBak);
});

it('should throw a meaningful error when initialized without an app object', function() {

(function() {
var worker = new Worker(null, {}, {}, function() {});
wr = new Worker(null, {}, {}, function() {});
}).should.throwError(/.*application.*/i);
});

it('should throw a meaningful error when initialized without a server instance', function() {

(function() {
var worker = new Worker({}, null, {}, function() {});
wr = new Worker({}, null, {}, function() {});
}).should.throwError(/.*server.*/i);
});
});
40 changes: 29 additions & 11 deletions tests/greppy/lib/configTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Tests for lib/helper/config.js
* Tests for lib/config.js
*
* @author Nabil Krause <nabil.krause@silberlicht.eu>
*/
Expand All @@ -13,21 +13,21 @@ var root = path.resolve(__dirname + '/../../../');
var Config = require(root + '/lib/config');
var cg = null;

describe('config', function() {
describe('Config', function() {

var configPath = '/tmp/greppy/';
var configFile = 'config.js';
var configMockup = {
propOne: {
stringProp: 'lorem',
numProp: 12,
arrayProp: ['yeah', 1]
},
propTwo: {
objProp: {
boolProp: false
}
propOne: {
stringProp: 'lorem',
numProp: 12,
arrayProp: ['yeah', 1]
},
propTwo: {
objProp: {
boolProp: false
}
}
};
var defaultMockup = {
defaultProp: 'justSomeText',
Expand All @@ -51,6 +51,7 @@ describe('config', function() {
describe('load', function() {

it('should throw an error if no path was provided', function() {

cg = new Config({});

(function() {
Expand All @@ -59,6 +60,7 @@ describe('config', function() {
});

it('should throw an error if a wrong path was provided', function() {

cg = new Config({});

(function() {
Expand All @@ -67,6 +69,7 @@ describe('config', function() {
});

it('should load a config on instanciation when a path property is passed to the constructor', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -75,6 +78,7 @@ describe('config', function() {
});

it('should load a config when it\'s path is provided as parameter', function() {

cg = new Config({});

cg.load(configPath + configFile);
Expand All @@ -86,12 +90,14 @@ describe('config', function() {
describe('get', function() {

it('should return null if no matching property exists', function() {

cg = new Config({});

should.deepEqual(null, cg.get('meow'));
});

it('should return the property matching the passed key', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -104,6 +110,7 @@ describe('config', function() {
});

it('should return the whole config if no argument was passed', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -115,6 +122,7 @@ describe('config', function() {
describe('set', function() {

it('should throw an error if an undefined value was passed as value', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -125,6 +133,7 @@ describe('config', function() {
});

it('should set a config key to the passed value', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -140,6 +149,7 @@ describe('config', function() {
});

it('should set the whole config if only one argument was passed', function() {

var newConfig = {
yeah: {
myProp: 'bla'
Expand All @@ -156,6 +166,7 @@ describe('config', function() {
});

it('should overwrite the default config with a provided one', function() {

var userConfig = {
defaultProp: ['okay'],
yo: {
Expand All @@ -179,6 +190,7 @@ describe('config', function() {
describe('setDefault', function() {

it('should throw an error if no arguments are passed', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -189,6 +201,7 @@ describe('config', function() {
});

it('should set a default config if one was passed as argument', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -202,6 +215,7 @@ describe('config', function() {
describe('getDefault', function() {

it('should return an empty object if no default config was specified', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -210,6 +224,7 @@ describe('config', function() {
});

it('should return a default config if one was specified', function() {

cg = new Config({
path: configPath + configFile
});
Expand All @@ -230,6 +245,7 @@ describe('config', function() {
};

it('should deep-merge a user defined config over the default config by default', function() {

var expected = extend(true, {}, defaultMockup, userConfig);

cg = new Config({
Expand All @@ -243,6 +259,7 @@ describe('config', function() {
});

it('should undeep-merge a user defined config over the default config if deep is set to false', function() {

var expected = extend(false, {}, defaultMockup, userConfig);

cg = new Config({
Expand All @@ -256,6 +273,7 @@ describe('config', function() {
});

it('should deep-merge a user defined config over the default config if deep is set to true', function() {

var expected = extend(true, {}, defaultMockup, userConfig);

cg = new Config({
Expand Down
6 changes: 5 additions & 1 deletion tests/greppy/lib/extension/datatype/arrayTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ var should = require('should');
var path = require('path');
var root = path.resolve(__dirname + '/../../../../../');

describe('extensions for the array type', function() {
describe('Extensions for Array', function() {

before(function() {
require(root + '/lib/extension/datatype/array');
});

describe('uniq', function() {
it('should change the number of elements of an array which has duplicate values', function() {

var myNums = [0, 1, 1, 2];
var myVals = ['abc', 'def', 'ghj', 'ghj'];
var mixed = ['abc', 'def', 0, 'def', 0, 1];
Expand All @@ -26,6 +27,7 @@ describe('extensions for the array type', function() {
});

it('should not change the number of elements of an array which has only unique values', function() {

var myNums = [0, 1, 2];
var myVals = ['yo', 'hi', 'test', 'kk'];

Expand All @@ -34,6 +36,7 @@ describe('extensions for the array type', function() {
});

it('should remove duplicate values of an array which has duplicate values', function() {

var myNums = [0, 1, 1, 2];
var myVals = ['abc', 'def', 'ghj', 'ghj'];
var mixed = ['abc', 'def', 0, 'def', 0, 1];
Expand All @@ -47,6 +50,7 @@ describe('extensions for the array type', function() {
});

it('should sort the values of a given array', function() {

var myNums = [3, 4, 1, 2];
var myVals = ['def', 'xyz', 'abc'];

Expand Down
Loading

0 comments on commit cf79bbf

Please sign in to comment.