Permalink
Browse files

rewrote tests using mocha

  • Loading branch information...
1 parent 4eb1fff commit 2c0d020652ea373abfc18ffc97f7fe30ff50f805 @jamesbloomer committed Oct 20, 2012
Showing with 190 additions and 176 deletions.
  1. +3 −3 lib/pivotaltracker.js
  2. +1 −1 lib/tadaa.js
  3. +3 −3 package.json
  4. +33 −31 test/pivotaltracker_test.js
  5. +112 −110 test/tadaa_test.js
  6. +38 −28 test/zendesk_test.js
View
6 lib/pivotaltracker.js
@@ -8,20 +8,20 @@ var getStories = function(filter, options, callback) {
return callback(error);
}
- console.log('Got %s open stories', ret.story.length);
+ console.log('Got %s open stories', ret.story.length);
return callback(null, ret.story.length);
});
};
var getOpenBugs = function(options, callback) {
var openBugsFilter = "type:bug state:unscheduled,unstarted,started,finished,delivered,rejected";
- return getStories(openBugsFilter, options, callback);
+ return getStories(openBugsFilter, options, callback);
};
var getOpenFeatures = function(options, callback) {
var openFeaturesFilter = "type:feature state:unscheduled,unstarted,started,finished,delivered,rejected";
- return getStories(openFeaturesFilter, options, callback);
+ return getStories(openFeaturesFilter, options, callback);
};
exports.getOpenBugs = getOpenBugs;
View
2 lib/tadaa.js
@@ -29,7 +29,7 @@ tadaa.getValueAndPlaySound = function(upSound, downSound, getValue, getValueOpti
tadaa.playCorrectSound(tadaa.current, result, up, down, player, function(error) {
tadaa.current = result;
return;
- });
+ });
});
};
View
6 package.json
@@ -22,10 +22,10 @@
"jshint" : "0.5.x",
"should" : "0.5.x",
"sinon" : "1.3.x",
- "vows" : "0.6.x"
+ "mocha" : "x.x.x"
},
"main": "./lib/tadaa",
"bin": { "tadaa": "./bin/tadaa" },
- "scripts": { "test": "vows test/*_test.js --spec" },
- "engines": { "node": ">= 0.4.12 < 0.7.0" }
+ "scripts": { "test": "mocha test/*_test.js --reporter spec" },
+ "engines": { "node": ">= 0.4.12 < 0.9.0" }
}
View
64 test/pivotaltracker_test.js
@@ -1,33 +1,35 @@
-var vows = require('vows'),
- should = require('should'),
- sinon = require('sinon'),
- pivotal = require("pivotal"),
- pivotaltracker = require('../lib/pivotaltracker.js');
+var mocha = require('mocha'),
+ assert = require('assert'),
+ sinon = require('sinon'),
+ pivotal = require("pivotal"),
+ pivotaltracker = require('../lib/pivotaltracker.js');
-vows.describe('Tadaa Pivotal Tracker Tests')
-.addBatch({
- 'when getOpenBugs called ' : {
- topic : function() {
+describe('Tadaa Pivotal Tracker Tests', function() {
+ describe('when getOpenBugs called', function() {
+ beforeEach(function() {
sinon.stub(pivotal, 'useToken');
- sinon.stub(pivotal, 'getStories').yields(null);
- pivotaltracker.getOpenBugs({ token: "myToken", projectId: "projectId" }, this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should call pivotal methods' : function(err, result) {
- // TODO change when token changes
- pivotal.useToken.calledWith('myToken').should.be.true;
- pivotal.getStories.calledWith('projectId', { filter: "type:bug state:unscheduled,unstarted,started,finished,delivered,rejected" }).should.be.true;
- },
- 'should get correct story length' : function(err, result) {
- // TODO
- should.not.exist(err);
- }
- },
- teardown: function() {
- pivotal.useToken.restore();
- pivotal.getStories.restore();
- }
-})
-.export(module);
+ sinon.stub(pivotal, 'getStories').yields(null, { story : { length : 1 } });
+ });
+
+ afterEach(function() {
+ pivotal.useToken.restore();
+ pivotal.getStories.restore();
+ });
+
+ it('should not error', function(done) {
+ pivotaltracker.getOpenBugs({ token: "myToken", projectId: "projectId" }, function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should call pivotal methods', function(done) {
+ pivotaltracker.getOpenBugs({ token: "myToken", projectId: "projectId" }, function(err) {
+ // TODO change when token changes
+ assert(pivotal.useToken.calledWith('myToken'));
+ assert(pivotal.getStories.calledWith('projectId', { filter: "type:bug state:unscheduled,unstarted,started,finished,delivered,rejected" }));
+ done();
+ });
+ });
+ });
+});
View
222 test/tadaa_test.js
@@ -1,118 +1,120 @@
-var vows = require('vows'),
- should = require('should'),
- sinon = require('sinon'),
- child = require('child_process'),
- tadaa = require('../lib/tadaa.js');
+var mocha = require('mocha'),
+ assert = require('assert'),
+ sinon = require('sinon'),
+ child = require('child_process'),
+ tadaa = require('../lib/tadaa.js');
-vows.describe('Tadaa Tests')
-.addBatch({
- 'when result is greater than current' : {
- topic : function() {
+describe('Tadaa', function() {
+ describe('when result is greater than current', function() {
+ beforeEach(function() {
sinon.stub(child, 'exec').yields(null);
- tadaa.playCorrectSound(1, 2, 'up.wav', 'down.wav', null, this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should play up.wav' : function() {
- child.exec.calledWith('aplay up.wav').should.be.true;
- }
- },
- teardown: function() {
- child.exec.restore();
- }
-})
-.addBatch({
- 'when result is less than current' : {
- topic : function() {
+ });
+
+ afterEach(function() {
+ child.exec.restore();
+ });
+
+ it('should not error when playCorrectSound called', function(done) {
+ tadaa.playCorrectSound(1, 2, 'up.wav', 'down.wav', null, function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should play up.wav', function(done) {
+ tadaa.playCorrectSound(1, 2, 'up.wav', 'down.wav', null, function(err) {
+ assert(child.exec.calledWith('aplay up.wav'));
+ done();
+ });
+ });
+ });
+
+ describe('when result is less than current', function() {
+ beforeEach(function() {
sinon.stub(child, 'exec').yields(null);
- tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', null, this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should play down.wav' : function(stub) {
- child.exec.calledWith('aplay down.wav').should.be.true;
- }
- },
- teardown: function() {
- child.exec.restore();
- }
-})
-.addBatch({
- 'when result is equal to current' : {
- topic : function() {
+ });
+
+ afterEach(function() {
+ child.exec.restore();
+ });
+
+ it('should not error when playCorrectSound called', function(done) {
+ tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', null, function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should play down.wav', function(done) {
+ tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', null, function(err) {
+ assert(child.exec.calledWith('aplay down.wav'));
+ done();
+ });
+ });
+ });
+
+ describe('when result is equal to current', function() {
+ beforeEach(function() {
sinon.stub(child, 'exec').yields(null);
- tadaa.playCorrectSound(1, 1, 'up.wav', 'down.wav', null, this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should not play a sound' : function(stub) {
- child.exec.called.should.be.false;
- }
- },
- teardown: function() {
- child.exec.restore();
- }
-})
-.addBatch({
- 'when audio player is set' : {
- topic : function() {
+ });
+
+ afterEach(function() {
+ child.exec.restore();
+ });
+
+ it('should not error when playCorrectSound called', function(done) {
+ tadaa.playCorrectSound(1, 1, 'up.wav', 'down.wav', null, function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should not play a sound', function(done) {
+ tadaa.playCorrectSound(1, 1, 'up.wav', 'down.wav', null, function(err) {
+ assert.equal(child.exec.called, false);
+ done();
+ });
+ });
+ });
+
+ describe('when audio player is set', function() {
+ beforeEach(function() {
sinon.stub(child, 'exec').yields(null);
- tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', 'afplay', this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should play down.wav with afplay' : function(stub) {
- child.exec.calledWith('afplay down.wav').should.be.true;
- }
- },
- teardown: function() {
- child.exec.restore();
- }
-})
-.addBatch({
- 'when start called' : {
- topic: function() {
- sinon.stub(tadaa, 'getValueAndPlaySound').yields(null);
+ });
+
+ afterEach(function() {
+ child.exec.restore();
+ });
+
+ it('should not error', function(done) {
+ tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', 'afplay', function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should play down.wav with afplay', function(done) {
+ tadaa.playCorrectSound(2, 1, 'up.wav', 'down.wav', 'afplay', function(err) {
+ assert(child.exec.calledWith('afplay down.wav'));
+ done();
+ });
+ });
+ });
+
+ describe('when start called', function() {
+ beforeEach(function() {
+ sinon.stub(tadaa, 'getValueAndPlaySound');
var clock = sinon.useFakeTimers();
tadaa.start(10, 'upsound', 'downSound', 'getValue', 'getValueOptions', 'audioPlayer');
- clock.tick(15);
- },
- 'should call getValueAndPlaySound': function(err, result) {
- tadaa.getValueAndPlaySound
- .calledOnce
- .should.be.true;
- }
- },
- teardown: function() {
- tadaa.getValueAndPlaySound.restore();
- }
-})
-/*
-.addBatch({
- 'when getValueAndPlaySound called' : {
- topic : function() {
- sinon.stub(tadaa, 'playCorrectSound').yields(null);
- var getValue = function(options, callback) {
- return callback(null, 1);
- };
-
- tadaa.getValueAndPlaySound('up', 'down', getValue);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should call playCorrectSound' : function(err, result) {
- tadaa.playCorrectSound.calledOnce.should.be.true;
- }
- },
- teardown: function() {
- tadaa.playCorrectSound.restore();
- }
-})
-*/
-.export(module);
+ clock.tick(15);
+ });
+
+ afterEach(function() {
+ tadaa.getValueAndPlaySound.restore();
+ });
+ it('should call getValueAndPlaySound', function() {
+ assert(tadaa.getValueAndPlaySound.calledOnce);
+ });
+ });
+});
View
66 test/zendesk_test.js
@@ -1,31 +1,41 @@
-var vows = require('vows'),
- should = require('should'),
- sinon = require('sinon'),
- buddha = require("buddha"),
- zendesk = require('../lib/zendesk.js');
+var mocha = require('mocha'),
+ assert = require('assert'),
+ sinon = require('sinon'),
+ buddha = require("buddha"),
+ zendesk = require('../lib/zendesk.js');
-vows.describe('Tadaa Zendesk Tests')
-.addBatch({
- 'when getOpenTickets called ' : {
- topic : function() {
+describe('Tadaa Zendesk Tests', function() {
+ describe('when getOpenTickets called', function(done) {
+ beforeEach(function() {
sinon.stub(buddha, 'setCredentials');
sinon.stub(buddha, 'getTicketCount').yields(null, 1);
- zendesk.getOpenTickets({ zenHost: "company.zendesk.com", zenEmail: "jon@a.com", zenPassword: "secure", zenView: "123456" }, this.callback);
- },
- 'should not error' : function(err, result) {
- should.not.exist(err);
- },
- 'should call buddha methods' : function(err, result) {
- buddha.setCredentials.calledWith('company.zendesk.com', 'jon@a.com', 'secure').should.be.true;
- buddha.getTicketCount.calledWith('123456').should.be.true;
- },
- 'should get correct ticket count' : function(err, result) {
- result.should.eql(1);
- }
- },
- teardown: function() {
- buddha.setCredentials.restore();
- buddha.getTicketCount.restore();
- }
-})
-.export(module);
+ });
+
+ afterEach(function() {
+ buddha.setCredentials.restore();
+ buddha.getTicketCount.restore();
+ });
+
+ it('should not error', function(done) {
+ zendesk.getOpenTickets({ zenHost: "company.zendesk.com", zenEmail: "jon@a.com", zenPassword: "secure", zenView: "123456" }, function(err) {
+ assert.equal(err, null);
+ done();
+ });
+ });
+
+ it('should call buddha methods', function(done) {
+ zendesk.getOpenTickets({ zenHost: "company.zendesk.com", zenEmail: "jon@a.com", zenPassword: "secure", zenView: "123456" }, function(err, result) {
+ assert(buddha.setCredentials.calledWith('company.zendesk.com', 'jon@a.com', 'secure'));
+ assert(buddha.getTicketCount.calledWith('123456'));
+ done();
+ });
+ });
+
+ it('should get correct ticket count', function(done) {
+ zendesk.getOpenTickets({ zenHost: "company.zendesk.com", zenEmail: "jon@a.com", zenPassword: "secure", zenView: "123456" }, function(err, result) {
+ assert.equal(result, 1);
+ done();
+ });
+ });
+ });
+});

0 comments on commit 2c0d020

Please sign in to comment.