Permalink
Browse files

Removing the ugly storage binding.

  • Loading branch information...
1 parent 5a3c46c commit 41825b54d50d52b855de1884af629028e7a79029 @vesln committed Jan 28, 2012
Showing with 34 additions and 37 deletions.
  1. +6 −13 lib/commands.js
  2. +28 −24 test/commands.test.js
View
@@ -32,11 +32,6 @@ var app = require('./app');
var storage = require('./storage');
/**
- * Storage alias.
- */
-commands.storage = storage;
-
-/**
* Prints current version.
*
* @api public
@@ -52,9 +47,8 @@ commands.version = function() {
* @api public
*/
commands.delete = function(key) {
- var self = this;
- this.storage.del(key, function() {
- self.storage.save(function(err) {
+ storage.del(key, function() {
+ storage.save(function(err) {
if (err) throw err;
});
});
@@ -67,7 +61,7 @@ commands.delete = function(key) {
* @api public
*/
commands.get = function(key) {
- this.storage.get(key, function(val) {
+ storage.get(key, function(val) {
print(val || 'Nothing found.');
});
};
@@ -79,9 +73,8 @@ commands.get = function(key) {
* @api public
*/
commands.set = function(key, value) {
- var self = this;
- this.storage.set(key, value, function() {
- self.storage.save(function(err) {
+ storage.set(key, value, function() {
+ storage.save(function(err) {
if (err) throw err;
});
});
@@ -93,7 +86,7 @@ commands.set = function(key, value) {
* @api public
*/
commands.list = function() {
- this.storage.get(function(data) {
+ storage.get(function(data) {
Object.keys(data).forEach(function(key) {
print(key + ': ' + data[key]);
});
View
@@ -9,14 +9,18 @@
* Module dependencies.
*/
var sinon = require('sinon');
-var clone = require('super');
+
+/**
+ * Support.
+ */
+var storage = require('../lib/storage');
/**
* The tests object.
*
* @type {Object}
*/
-var commands = clone(require('../lib/commands'), {});
+var commands = require('../lib/commands');
describe('commands', function() {
describe('.version()', function() {
@@ -27,47 +31,47 @@ describe('commands', function() {
describe('.delete()', function() {
it('should call storage.delete and storage.save', function() {
- sinon.spy(commands.storage, 'del');
- sinon.stub(commands.storage, 'save');
+ sinon.spy(storage, 'del');
+ sinon.stub(storage, 'save');
commands.delete('foo');
- commands.storage.del.calledOnce.should.be.ok;
- commands.storage.del.getCall(0).args[0].should.eql('foo');
- commands.storage.save.calledOnce.should.be.ok;
- commands.storage.del.restore();
- commands.storage.save.restore();
+ storage.del.calledOnce.should.be.ok;
+ storage.del.getCall(0).args[0].should.eql('foo');
+ storage.save.calledOnce.should.be.ok;
+ storage.del.restore();
+ storage.save.restore();
});
});
describe('.get()', function() {
it('should call storage.get', function() {
- sinon.stub(commands.storage, 'get');
+ sinon.stub(storage, 'get');
commands.get('foo');
- commands.storage.get.getCall(0).args[0].should.eql('foo');
- commands.storage.get.calledOnce.should.be.ok;
- commands.storage.get.restore();
+ storage.get.getCall(0).args[0].should.eql('foo');
+ storage.get.calledOnce.should.be.ok;
+ storage.get.restore();
});
});
describe('.set()', function() {
it('should call storage.set and storage.save', function() {
- sinon.spy(commands.storage, 'set');
- sinon.stub(commands.storage, 'save');
+ sinon.spy(storage, 'set');
+ sinon.stub(storage, 'save');
commands.set('foo', 'bar');
- commands.storage.set.calledOnce.should.be.ok;
- commands.storage.set.getCall(0).args[0].should.eql('foo');
- commands.storage.set.getCall(0).args[1].should.eql('bar');
- commands.storage.save.calledOnce.should.be.ok;
- commands.storage.set.restore();
- commands.storage.save.restore();
+ storage.set.calledOnce.should.be.ok;
+ storage.set.getCall(0).args[0].should.eql('foo');
+ storage.set.getCall(0).args[1].should.eql('bar');
+ storage.save.calledOnce.should.be.ok;
+ storage.set.restore();
+ storage.save.restore();
});
});
describe('.list()', function() {
it('should call storage.get with no params', function() {
- sinon.stub(commands.storage, 'get');
+ sinon.stub(storage, 'get');
commands.get('foo');
- commands.storage.get.calledOnce.should.be.ok;
- commands.storage.get.restore();
+ storage.get.calledOnce.should.be.ok;
+ storage.get.restore();
});
});
});

0 comments on commit 41825b5

Please sign in to comment.