Remove hashlib dependency and switch to mocha for testing

This commit is contained in:
John Crepezzi 2012-01-13 11:16:42 -05:00
parent b251978422
commit 6e4c087319
7 changed files with 42 additions and 65 deletions

View file

@ -1,17 +1,20 @@
var DocumentHandler = require('../lib/document_handler');
var Generator = require('../lib/key_generators/random');
describe('document_handler', function() {
describe('randomKey', function() {
it('should choose a key of the proper length', function() {
var dh = new DocumentHandler({ keyLength: 6 });
expect(dh.randomKey().length).toBe(6);
var gen = new Generator();
var dh = new DocumentHandler({ keyLength: 6, keyGenerator: gen });
dh.acceptableKey().length.should.equal(6);
});
it('should choose a default key length', function() {
var dh = new DocumentHandler();
expect(dh.keyLength).toBe(DocumentHandler.defaultKeyLength);
var gen = new Generator();
var dh = new DocumentHandler({ keyGenerator: gen });
dh.keyLength.should.equal(DocumentHandler.defaultKeyLength);
});
});

View file

@ -15,73 +15,34 @@ describe('redis_document_store', function() {
describe('set', function() {
it('should be able to set a key and have an expiration set', function() {
it('should be able to set a key and have an expiration set', function(done) {
var store = new RedisDocumentStore({ expire: 10 });
runs(function() {
var _this = this;
store.set('hello1', 'world', function(worked) {
_this.result = worked;
});
});
waitsFor(function() {
return typeof(this.result) === 'boolean';
});
runs(function() {
var _this = this;
store.set('hello1', 'world', function() {
RedisDocumentStore.client.ttl('hello1', function(err, res) {
expect(res).toBeGreaterThan(1);
_this.done = true;
res.should.be.above(1);
done();
});
});
waitsFor(function() {
return this.done;
});
});
it('should not set an expiration when told not to', function() {
it('should not set an expiration when told not to', function(done) {
var store = new RedisDocumentStore({ expire: 10 });
runs(function() {
var _this = this;
store.set('hello2', 'world', function(worked) {
_this.result = worked;
}, true);
});
waitsFor(function() {
return typeof(this.result) === 'boolean';
});
runs(function() {
var _this = this;
store.set('hello2', 'world', function() {
RedisDocumentStore.client.ttl('hello2', function(err, res) {
expect(res).toBe(-1);
_this.done = true;
res.should.equal(-1);
done();
});
});
waitsFor(function() {
return this.done;
});
}, true);
});
it('should not set an expiration when expiration is off', function() {
it('should not set an expiration when expiration is off', function(done) {
var store = new RedisDocumentStore({ expire: false });
runs(function() {
var _this = this;
store.set('hello3', 'world', function(worked) {
_this.result = worked;
});
});
waitsFor(function() {
return typeof(this.result) === 'boolean';
});
runs(function() {
var _this = this;
store.set('hello3', 'world', function(worked) {
RedisDocumentStore.client.ttl('hello3', function(err, res) {
expect(res).toBe(-1);
_this.done = true;
res.should.equal(-1);
done();
});
});
waitsFor(function() {
return this.done;
});
});
});