Skip to content
Browse files

Even nicer test

  • Loading branch information...
1 parent 9dfbcfb commit 67c77dc8d32ce2d366db03f3b3ab167900dbd53d @felixge committed Nov 15, 2011
Showing with 9 additions and 7 deletions.
  1. +9 −7 test/unit/test-client.js
View
16 test/unit/test-client.js
@@ -5,17 +5,17 @@ var sinon = require('sinon');
var CarbonClient = require(common.dir.lib + '/carbon_client');
var client;
-var fakeSocket;
+var writeStub;
test('write', {
before: function() {
- fakeSocket = {write: sinon.stub()};
- client = new CarbonClient({socket: fakeSocket});
+ writeStub = sinon.stub();
+ client = new CarbonClient({socket: {write: writeStub}});
},
'with single payload': function() {
client.write('foo.bar', 25);
- var write = fakeSocket.write.args.shift();
+ var write = writeStub.args.shift();
assert.ok(/^foo\.bar 25 [\d]+\n/.test(write[0]));
assert.equal(write[1], 'utf8');
assert.equal(write[2], undefined);
@@ -25,7 +25,7 @@ test('write', {
var cb = function() {};
client.write('foo.bar', 25, cb);
- var write = fakeSocket.write.args.shift();
+ var write = writeStub.args.shift();
assert.ok(/^foo\.bar 25 [\d]+\n/.test(write[0]));
assert.equal(write[2], cb);
},
@@ -34,7 +34,7 @@ test('write', {
var cb = function() {};
client.write('foo.bar', 25, 2001, cb);
- var write = fakeSocket.write.args.shift();
+ var write = writeStub.args.shift();
assert.ok(/^foo\.bar 25 2\n/.test(write[0]));
assert.equal(write[2], cb);
},
@@ -46,7 +46,9 @@ test('write', {
{path: 'two', value: 33, timestamp: 8000},
], cb);
- var write = fakeSocket.write.args.shift();
+ assert.equal(writeStub.args.length, 1);
+
+ var write = writeStub.args.shift();
assert.ok(/^one 30 9\ntwo 33 8\n/.test(write[0]));
assert.equal(write[2], cb);
}

0 comments on commit 67c77dc

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