Skip to content

Commit

Permalink
Some minor test refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Jun 22, 2011
1 parent 245eb45 commit 33ba3af
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 304 deletions.
56 changes: 21 additions & 35 deletions test/cursor_test.js
Expand Up @@ -45,13 +45,11 @@ var tests = testCase({
// Create a non-unique index and test inserts
client.createCollection('test_array', function(err, collection) {
collection.insert({'b':[1, 2, 3]}, {safe:true}, function(err, ids) {
collection.find(function(err, cursor) {
cursor.toArray(function(err, documents) {
test.deepEqual([1, 2, 3], documents[0].b);
// Let's close the db
test.done();
});
}, {});
collection.find().toArray(function(err, documents) {
test.deepEqual([1, 2, 3], documents[0].b);
// Let's close the db
test.done();
});
});
});
},
Expand Down Expand Up @@ -136,23 +134,17 @@ var tests = testCase({
},

function finished() {
collection.find(function(err, cursor) {
cursor.count(function(err, count) {
collection.find().count(function(err, count) {
test.equal(10, count);
test.ok(count.constructor == Number);
});
});

collection.find({}, {'limit':5}, function(err, cursor) {
cursor.count(function(err, count) {
test.equal(10, count);
});
collection.find({}, {'limit':5}).count(function(err, count) {
test.equal(10, count);
});

collection.find({}, {'skip':5}, function(err, cursor) {
cursor.count(function(err, count) {
test.equal(10, count);
});
collection.find({}, {'skip':5}).count(function(err, count) {
test.equal(10, count);
});

collection.find(function(err, cursor) {
Expand Down Expand Up @@ -345,10 +337,8 @@ var tests = testCase({
},

function finished() {
collection.find(function(err, cursor) {
cursor.count(function(err, count) {
test.equal(10, count);
});
collection.find().count(function(err, count) {
test.equal(10, count);
});

collection.find(function(err, cursor) {
Expand Down Expand Up @@ -929,12 +919,10 @@ var tests = testCase({
shouldCorrectlyExecuteCursorCountWithFields : function(test) {
client.createCollection('test_count_with_fields', function(err, collection) {
collection.save({'x':1, 'a':2}, {safe:true}, function(err, doc) {
collection.find({}, {'fields':['a']}, function(err, cursor) {
cursor.toArray(function(err, items) {
test.equal(1, items.length);
test.equal(2, items[0].a);
test.equal(null, items[0].x);
});
collection.find({}, {'fields':['a']}).toArray(function(err, items) {
test.equal(1, items.length);
test.equal(2, items[0].a);
test.equal(null, items[0].x);
});

collection.findOne({}, {'fields':['a']}, function(err, item) {
Expand All @@ -949,13 +937,11 @@ var tests = testCase({
shouldCorrectlyCountWithFieldsUsingExclude : function(test) {
client.createCollection('test_count_with_fields_using_exclude', function(err, collection) {
collection.save({'x':1, 'a':2}, {safe:true}, function(err, doc) {
collection.find({}, {'fields':{'x':0}}, function(err, cursor) {
cursor.toArray(function(err, items) {
test.equal(1, items.length);
test.equal(2, items[0].a);
test.equal(null, items[0].x);
test.done();
});
collection.find({}, {'fields':{'x':0}}).toArray(function(err, items) {
test.equal(1, items.length);
test.equal(2, items[0].a);
test.equal(null, items[0].x);
test.done();
});
});
});
Expand Down

0 comments on commit 33ba3af

Please sign in to comment.