Skip to content
Browse files

migrated all specs to mocha

  • Loading branch information...
1 parent 4f3b6cd commit 1e8c887b2efb0309f780dd0dec7a032f74f84685 @masylum committed May 8, 2012
View
16 Makefile
@@ -1,7 +1,7 @@
-NODE = node
MOCHA = ./node_modules/.bin/mocha --reporter spec
-test: test_model test_validator test_proxy test_update_document test_namespacer test_mapper test_integration
+test:
+ @$(MOCHA)
test_model:
@$(MOCHA) test/model_test
@@ -10,16 +10,18 @@ test_validator:
@$(MOCHA) test/validator_test.js
test_update_document:
- @$(NODE) test/helpers/update_document_test.js
+ @$(MOCHA) test/helpers_update_document_test.js
test_namespacer:
- @$(MOCHA) test/helpers/namespacer_test.js
+ @$(MOCHA) test/helpers_namespacer_test.js
test_mapper:
- @$(MOCHA) test/helpers/mapper_test.js
+ @$(MOCHA) test/helpers_mapper_test.js
test_proxy:
- @$(NODE) test/helpers/collection_proxy_test.js
+ @$(MOCHA) test/helpers_collection_proxy_test.js
test_integration:
- @$(MOCHA) test/integration/integration_test.js
+ @$(MOCHA) test/integration_test.js
+
+.PHONY: test
View
68 test/helpers/collection_proxy_test.js → test/helpers_collection_proxy_test.js
@@ -1,22 +1,23 @@
-var testosterone = require('testosterone')({post: 3000, sync: true, title: 'mongolia/helpers/collection_proxy.js'}),
- assert = testosterone.assert,
- gently = global.GENTLY = new (require('gently'))(),
- CollectionProxy = require('./../../lib/helpers/collection_proxy'),
- Collection = require('mongodb/lib/mongodb/collection').Collection.prototype,
- Model;
+/*globals describe, it, beforeEach*/
+var assert = require('assert')
+ , gently = global.GENTLY = new (require('gently'))()
+ , CollectionProxy = require('./../lib/helpers/collection_proxy')
+ , Collection = require('mongodb/lib/mongodb/collection').Collection.prototype
+ , Model;
function _stubGetCollection() {
gently.expect(Model, 'getCollection', function (_callback) {
_callback(null, Collection);
});
}
-testosterone
- .before(function () {
- Model = require('../../').model({}, 'models');
- })
+describe('collection proxy test', function () {
- .add('`proxy` delegates every call to collection_proxy or native driver collection functions', function () {
+ beforeEach(function () {
+ Model = require('../').model({}, 'models');
+ });
+
+ it('`proxy` delegates every call to collection_proxy or native driver collection functions', function () {
var cb = function cb() {},
args = ['zemba', cb];
@@ -41,9 +42,9 @@ testosterone
CollectionProxy.proxy(Model, {method: method, hooks: false}, args, cb);
});
- })
+ });
- .add('`proxy` modifies the arguments according to `namespaces` unless the `namespacing` option is set to `false`', function () {
+ it('`proxy` modifies the arguments according to `namespaces` unless the `namespacing` option is set to `false`', function () {
var cb = function () {},
args = [{foo: 'bar'}, cb];
@@ -75,9 +76,9 @@ testosterone
});
CollectionProxy.proxy(Model, {method: 'find', namespace: 'foo', namespacing: false}, args, cb);
- })
+ });
- .add('`proxy` maps the arguments according to `maps` unless the `mapping` option is set to `false`', function () {
+ it('`proxy` maps the arguments according to `maps` unless the `mapping` option is set to `false`', function () {
var cb = function () {},
args = [{foo: 'bar', _id: '3'}, cb];
@@ -104,9 +105,9 @@ testosterone
});
CollectionProxy.proxy(Model, {method: 'find', mapping: false}, args, cb);
- })
+ });
- .add('`proxy` can be called with no callback', function () {
+ it('`proxy` can be called with no callback', function () {
var args = ['zemba'];
['update', 'insert', 'findArray'].forEach(function (method) {
@@ -130,9 +131,9 @@ testosterone
CollectionProxy.proxy(Model, {method: method, hooks: false}, args);
});
- })
+ });
- .add('`findArray` calls find on a collection with some arguments', function () {
+ it('`findArray` calls find on a collection with some arguments', function () {
var cb = function (error, cursor) {},
cursor = {fleiba: 'zemba'},
error_result = null,
@@ -145,9 +146,9 @@ testosterone
});
CollectionProxy.findArray(Model, Collection, args, cb);
- })
+ });
- .add('`insert` inserts a record', function () {
+ it('`insert` inserts a record', function () {
var callback_called = false,
cb = function (error, ret) {
assert.deepEqual(error, null);
@@ -176,9 +177,9 @@ testosterone
});
CollectionProxy.insert(Model, Collection, args, cb);
- })
+ });
- .add('`update` finds and modifies a record', function () {
+ it('`update` finds and modifies a record', function () {
var callback_called = false,
cb = function (error, ret) {
assert.deepEqual(error, null);
@@ -211,9 +212,9 @@ testosterone
});
CollectionProxy.update(Model, Collection, args, cb);
- })
+ });
- .add('`findAndModify` finds and modifies a record', function () {
+ it('`findAndModify` finds and modifies a record', function () {
var callback_called = false,
cb = function (error, ret) {
assert.deepEqual(error, null);
@@ -246,9 +247,9 @@ testosterone
});
CollectionProxy.findAndModify(Model, Collection, args, cb);
- })
+ });
- .add('`mapReduceCursor` calls `mapReduce` returning a cursor', function () {
+ it('`mapReduceCursor` calls `mapReduce` returning a cursor', function () {
var args = ['a', 'b'],
coll = {foo: 'bar'};
@@ -280,9 +281,9 @@ testosterone
CollectionProxy.mapReduceCursor(Model, Collection, args, cb);
});
- })
+ });
- .add('`mapReduceArray` returns a `mapReduceCursor` to Array', function () {
+ it('`mapReduceArray` returns a `mapReduceCursor` to Array', function () {
var cb = function () {},
args = ['fleiba', cb],
cursor = {};
@@ -300,9 +301,9 @@ testosterone
});
CollectionProxy.mapReduceArray(Model, Collection, args, cb);
- })
+ });
- .add('`remove` removes a document', function () {
+ it('`remove` removes a document', function () {
var callback_called = false,
cb = function (error, ret) {
assert.deepEqual(error, null);
@@ -331,6 +332,5 @@ testosterone
});
CollectionProxy.remove(Model, Collection, args, cb);
- })
-
- .run();
+ });
+});
View
2 test/helpers/mapper_test.js → test/helpers_mapper_test.js
@@ -1,6 +1,6 @@
/*global describe, it*/
var assert = require('assert')
- , Mapper = require('./../../lib/helpers/mapper');
+ , Mapper = require('./../lib/helpers/mapper');
describe('mapper', function () {
it('`mapDocument` should filter documents before being inserted or updated', function () {
View
2 test/helpers/namespacer_test.js → test/helpers_namespacer_test.js
@@ -1,6 +1,6 @@
/*globals describe, it*/
var assert = require('assert')
- , Namespacer = require('./../../lib/helpers/namespacer');
+ , Namespacer = require('./../lib/helpers/namespacer');
describe('namespacer', function () {
it('`resolveNamespace` implements the whole namespace API', function () {
View
135 test/helpers/update_document_test.js → test/helpers_update_document_test.js
@@ -1,168 +1,168 @@
-var testosterone = require('testosterone')({post: 3000, sync: true, title: 'mongolia/helpers/update_document.js'}),
- assert = testosterone.assert,
- UpdateDocument = require('./../../lib/helpers/update_document');
+/*globals describe, it*/
+var assert = require('assert')
+ , UpdateDocument = require('./../lib/helpers/update_document');
-testosterone
+describe('namespacer', function () {
- .add('should return update document if its not an special operation', function () {
+ it('should return update document if its not an special operation', function () {
var update = {foo: 'bar'}
, doc = {foo: 'zemba', hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, update);
- })
+ });
- .add('`$inc` increases doc value', function () {
+ it('`$inc` increases doc value', function () {
var update = {'$inc': {foo: 3}}
, doc = {foo: 1, hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: 4, hey: 'joe'});
- })
+ });
- .add('`$inc` increases doc value using `dot_notation`', function () {
+ it('`$inc` increases doc value using `dot_notation`', function () {
var update = {'$inc': {'foo.bar': 3}}
, doc = {foo: {bar: 1}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: 4}});
- })
+ });
- .add('`$inc` sets doc value using `dot_notation` on `inexistant` elements', function () {
+ it('`$inc` sets doc value using `dot_notation` on `inexistant` elements', function () {
var update = {'$inc': {'foo.bar': 3}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: 3}});
- })
+ });
- .add('`$set` sets doc value', function () {
+ it('`$set` sets doc value', function () {
var update = {'$set': {foo: 'zemba'}}
, doc = {foo: 'bar', hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: 'zemba', hey: 'joe'});
- })
+ });
- .add('`$set` sets doc value using `dot_notation`', function () {
+ it('`$set` sets doc value using `dot_notation`', function () {
var update = {'$set': {'foo.bar': 'zemba'}}
, doc = {foo: {bar: 'joe'}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: 'zemba'}});
- })
+ });
- .add('`$set` sets doc value using `dot_notation` on `inexistant` elements', function () {
+ it('`$set` sets doc value using `dot_notation` on `inexistant` elements', function () {
var update = {'$set': {'foo.bar': 'zemba'}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: 'zemba'}});
- })
+ });
- .add('`$unset` unsets doc value', function () {
+ it('`$unset` unsets doc value', function () {
var update = {'$unset': {foo: 1}}
, doc = {foo: 'bar', hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {hey: 'joe'});
- })
+ });
- .add('`$unset` unsets doc value using `dot_notation`', function () {
+ it('`$unset` unsets doc value using `dot_notation`', function () {
var update = {'$unset': {'foo.bar.hey': 1}}
, doc = {foo: {bar: {hey: 'joe'}}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: {}}});
- })
+ });
- .add('`$unset` unsets doc value using `dot_notation` on `inexistant` elements', function () {
+ it('`$unset` unsets doc value using `dot_notation` on `inexistant` elements', function () {
var update = {'$unset': {'foo.bar.hey': 1}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {});
- })
+ });
- .add('`$push` pushes doc value', function () {
+ it('`$push` pushes doc value', function () {
var update = {'$push': {foo: 'fleiba'}}
, doc = {foo: ['bar'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['bar', 'fleiba'], hey: 'joe'});
- })
+ });
- .add('`$push` pushes doc value using `dot_notation`', function () {
+ it('`$push` pushes doc value using `dot_notation`', function () {
var update = {'$push': {'foo.bar': 'fleiba'}}
, doc = {foo: {bar: ['bar']}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['bar', 'fleiba']}});
- })
+ });
- .add('`$push` pushes doc value using `dot_notation` on `inexistant` elements', function () {
+ it('`$push` pushes doc value using `dot_notation` on `inexistant` elements', function () {
var update = {'$push': {'foo.bar': 'fleiba'}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['fleiba']}});
- })
+ });
- .add('`$pushAll` pushes doc array', function () {
+ it('`$pushAll` pushes doc array', function () {
var update = {'$pushAll': {foo: ['zemba', 'fleiba']}}
, doc = {foo: ['bar'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['bar', 'zemba', 'fleiba'], hey: 'joe'});
- })
+ });
- .add('`$pushAll` pushes doc array using `dot_notation`', function () {
+ it('`$pushAll` pushes doc array using `dot_notation`', function () {
var update = {'$pushAll': {'foo.bar': ['zemba', 'fleiba']}}
, doc = {foo: {bar: ['bar']}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['bar', 'zemba', 'fleiba']}});
- })
+ });
- .add('`$pushAll` pushes doc array using `dot_notation` on `inexistant` elements', function () {
+ it('`$pushAll` pushes doc array using `dot_notation` on `inexistant` elements', function () {
var update = {'$pushAll': {'foo.bar': ['zemba', 'fleiba']}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['zemba', 'fleiba']}});
- })
+ });
- .add('`$addToSet` pushes doc value if not present', function () {
+ it('`$addToSet` pushes doc value if not present', function () {
[0, 1].forEach(function () {
var update = {'$addToSet': {foo: 'zemba'}}
, doc = {foo: ['bar'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['bar', 'zemba'], hey: 'joe'});
});
- })
+ });
- .add('`$addToSet` pushes doc value if not present using `dot_notation`', function () {
+ it('`$addToSet` pushes doc value if not present using `dot_notation`', function () {
[0, 1].forEach(function () {
var update = {'$addToSet': {'foo.bar': 'zemba'}}
, doc = {foo: {bar: ['bar']}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['bar', 'zemba']}});
});
- })
+ });
- .add('`$addToSet` pushes doc value if not present using `dot_notation` on `inexistant` elements', function () {
+ it('`$addToSet` pushes doc value if not present using `dot_notation` on `inexistant` elements', function () {
[0, 1].forEach(function () {
var update = {'$addToSet': {'foo.bar': 'zemba'}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['zemba']}});
});
- })
+ });
- .add('`$pop` pops array element', function () {
+ it('`$pop` pops array element', function () {
var update = {'$pop': {foo: 1}}
, doc = {foo: ['bar', 'zemba', 'fleiba'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
@@ -174,9 +174,9 @@ testosterone
ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['zemba', 'fleiba'], hey: 'joe'});
- })
+ });
- .add('`$pop` pops array element using `dot_notation`', function () {
+ it('`$pop` pops array element using `dot_notation`', function () {
var update = {'$pop': {'foo.bar': 1}}
, doc = {foo: {bar: ['bar', 'zemba', 'fleiba']}}
, ret = UpdateDocument({document: doc, update: update});
@@ -188,86 +188,85 @@ testosterone
ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['zemba', 'fleiba']}});
- })
+ });
- .add('`$pop` pops array element using `dot_notation` on `inexistant` elements', function () {
+ it('`$pop` pops array element using `dot_notation` on `inexistant` elements', function () {
var update = {'$pop': {'foo.bar': 1}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {});
- })
+ });
- .add('`$pull` removes array elements matchin a value', function () {
+ it('`$pull` removes array elements matchin a value', function () {
var update = {'$pull': {foo: 'zemba'}}
, doc = {foo: ['bar', 'zemba', 'zemba', 'fleiba'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['bar', 'fleiba'], hey: 'joe'});
- })
+ });
- .add('`$pull` removes array elements matchin a value using `dot_notation`', function () {
+ it('`$pull` removes array elements matchin a value using `dot_notation`', function () {
var update = {'$pull': {'foo.bar': 'zemba'}}
, doc = {foo: {bar: ['bar', 'zemba', 'zemba', 'fleiba']}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['bar', 'fleiba']}});
- })
+ });
- .add('`$pull` removes array elements matchin a value using `dot_notation` on `inexistant` elements', function () {
+ it('`$pull` removes array elements matchin a value using `dot_notation` on `inexistant` elements', function () {
var update = {'$pull': {'foo.bar': 'zemba'}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {});
- })
+ });
- .add('`$pullAll` removes array elements in a array', function () {
+ it('`$pullAll` removes array elements in a array', function () {
var update = {'$pullAll': {foo: ['fleiba', 'zemba']}}
, doc = {foo: ['bar', 'zemba', 'zemba', 'fleiba'], hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: ['bar'], hey: 'joe'});
- })
+ });
- .add('`$pullAll` removes array elements in a array using `dot_notation`', function () {
+ it('`$pullAll` removes array elements in a array using `dot_notation`', function () {
var update = {'$pullAll': {'foo.bar': ['fleiba', 'zemba']}}
, doc = {foo: {bar: ['bar', 'zemba', 'zemba', 'fleiba']}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {bar: ['bar']}});
- })
+ });
- .add('`$pullAll` removes array elements in a array using `dot_notation` on `inexistant` elements', function () {
+ it('`$pullAll` removes array elements in a array using `dot_notation` on `inexistant` elements', function () {
var update = {'$pullAll': {'foo.bar': ['fleiba', 'zemba']}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {});
- })
+ });
- .add('`$rename` renames a field', function () {
+ it('`$rename` renames a field', function () {
var update = {'$rename': {foo: 'bar'}}
, doc = {foo: 'foo', hey: 'joe'}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {bar: 'foo', hey: 'joe'});
- })
+ });
- .add('`$rename` renames a field using `dot_notation`', function () {
+ it('`$rename` renames a field using `dot_notation`', function () {
var update = {'$rename': {'foo.bar': 'far'}}
, doc = {foo: {bar: 'foo'}}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {foo: {far: 'foo'}});
- })
+ });
- .add('`$rename` renames a field using `dot_notation` on `inexistant` elements', function () {
+ it('`$rename` renames a field using `dot_notation` on `inexistant` elements', function () {
var update = {'$rename': {'foo.bar': 'far'}}
, doc = {}
, ret = UpdateDocument({document: doc, update: update});
assert.deepEqual(ret, {});
- })
-
- .run();
+ });
+});
View
2 test/integration/integration_test.js → test/integration_test.js
@@ -1,7 +1,7 @@
/*globals describe, it, before*/
var assert = require('assert')
- , Model = require('./../../lib/model')
+ , Model = require('./../lib/model')
, mongodb = require('mongodb')
, Db = mongodb.Db
, Server = mongodb.Server

0 comments on commit 1e8c887

Please sign in to comment.
Something went wrong with that request. Please try again.