Permalink
Browse files

refactored registry tests, fixed some glitches in registry

  • Loading branch information...
schaermu committed May 31, 2012
1 parent 5b33556 commit d355397037aa902a25d324e86e4b4c7307e22088
Showing with 23 additions and 18 deletions.
  1. +1 −2 lib/registry.js
  2. +22 −16 test/registry.test.js
View
@@ -2,12 +2,11 @@ exports = module.exports = {
instance: {
values: [],
getIndex: function(name) {
- for (var i = 0; i < this.registry.length; i++) {
+ for (var i = 0; i < this.values.length; i++) {
if (this.values[i].name === name) {
return i;
}
}
- return null;
},
set : function(name, value) {
if (this.get(name) === false) {
View
@@ -1,23 +1,29 @@
-var ffmpeg = require('../lib/fluent-ffmpeg'),
- Registry = require('../lib/registry'),
- testCase = require('nodeunit').testCase;
+var ffmpeg = require('../lib/');
+ Registry = process.env.FLUENTFFMPEG_COV ? require('../lib-cov/registry') : require('../lib/registry');
// reset registry
Registry.instance.reset();
-module.exports = testCase({
- testCanSetValue: function(test) {
+describe('Registry.set', function() {
+ it('should set a value in the global registry', function() {
Registry.instance.set('foo', 'bar');
- test.ok(Registry.instance.values.length === 1);
- test.done();
- },
- testCanGetValue: function(test) {
+ Registry.instance.values.length.should.equal(1);
+ });
+ it('should update a value that was already set', function() {
+ Registry.instance.set('foo', 'bar-new');
+ Registry.instance.get('foo').should.equal('bar-new');
+
+ // re-set to old value
+ Registry.instance.set('foo', 'bar');
+ });
+});
+
+describe('Registry.get', function() {
+ it('should return the value for a certain key from the global registry', function() {
var val = Registry.instance.get('foo');
- test.ok(val === 'bar');
- test.done();
- },
- testReturnsNullOnKeyNotFound: function(test) {
- test.ok(Registry.instance.get('bar') === null);
- test.done();
- }
+ val.should.equal('bar');
+ });
+ it('should return false when key is not present', function() {
+ Registry.instance.get('NOTFOUND').should.be.false;
+ });
});

0 comments on commit d355397

Please sign in to comment.