Permalink
Browse files

Cleanup CoffeeScript test.

  • Loading branch information...
1 parent 0e7acfb commit aa7f9dabbbbf29bde2c651ed2005e939b19b30a1 @jprichardson committed Jan 24, 2013
Showing with 78 additions and 184 deletions.
  1. +2 −2 lib/triggerflow.js
  2. +0 −75 test/triggerflow.test.coffee
  3. +76 −107 test/triggerflow.test.js
View
@@ -18,10 +18,10 @@ TriggerFlow.prototype.update = function(partialObject) {
_this.object[key] = val
})
- var allTrue = Object.keys(_this.object).map(function(key) { return _this.object[key]}).every(function(val) {
+ var allTrue = Object.keys(_this.object).map(function(key) { return _this.object[key] }).every(function(val) {
if (typeof val === 'boolean') return val;
if (typeof val === 'number') return val === 0;
- else return !!val
+ else return !!val //convert to boolean
})
if (!allTrue) return
@@ -1,75 +0,0 @@
-tutil = require('testutil')
-{TriggerFlow} = require('../lib/triggerflow')
-util = require('util')
-fs = require('fs-extra')
-path = require('path-extra')
-
-describe 'TriggerFlow', ->
- it 'should fire the event when the conditions are met', (done) ->
- processing = 0
- tf = TriggerFlow.create done: false, processing: processing, ->
- T tf.hasTriggered
- done()
-
- setTimeout(->
- tf.update(done: true)
- ,5)
-
- again = ->
- processing += 1
- tf.update(processing: processing)
- setTimeout(->
- processing -= 1
- tf.update(processing: processing)
- ,10)
- again()
-
- it 'should fire the event when the conditions are met and retrieve the expected parameters', (done) ->
- ARBITRARY_STRING = 'hello'
- ARBITRATY_NUM = 29
-
- processing = 0
- tf = TriggerFlow.create done: false, processing: processing, (someNum, someString) ->
- T someNum is ARBITRATY_NUM
- T someString is ARBITRARY_STRING
- T tf.hasTriggered
- done()
-
- setTimeout(->
- tf.update(done: true)
- ,5)
-
- again = ->
- processing += 1
- tf.update(processing: processing, ARBITRATY_NUM, ARBITRARY_STRING)
- setTimeout(->
- processing -= 1
- tf.update(processing: processing, ARBITRATY_NUM, ARBITRARY_STRING)
- ,10)
- again()
-
- it 'should count down and fire the event when the conditions are met', (done) ->
- counter = 10
- tf = TriggerFlow.create counter: counter, ->
- T counter is 0
- clearInterval(decrementer)
- T tf.hasTriggered
- done()
-
- decrementer = setInterval(->
- counter -= 1
- tf.update counter: counter
- ,5)
-
- it 'should automatically count down if the number is negative and then fire the event when the conditions are met', (done) ->
- tf = TriggerFlow.create counter: 10, ->
- T tf.object.counter is 0
- clearInterval(decrementer)
- T tf.hasTriggered
- done()
-
- decrementer = setInterval(->
- tf.update counter: -1
- ,5)
-
-
View
@@ -1,114 +1,83 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var TriggerFlow, fs, path, tutil, util;
+var tutil = require('testutil')
+ , TriggerFlow = require('../lib/triggerflow').TriggerFlow
+ , trigger = require('../lib/triggerflow')
+ , util = require('util')
+ , fs = require('fs-extra')
- tutil = require('testutil');
- TriggerFlow = require('../lib/triggerflow').TriggerFlow;
+describe('TriggerFlow', function() {
+ it('should fire the event when the conditions are met', function(done) {
+ var processing = 0
+ var tf = trigger({done: false, processing: processing}, function() {
+ T (tf.hasTriggered);
+ done()
+ })
+
+ setTimeout(function() {
+ tf.update({done: true})
+ }, 5)
- util = require('util');
+ function again() {
+ processing += 1
+ tf.update({processing: processing})
+ setTimeout(function() {
+ processing -= 1;
+ tf.update({processing: processing})
+ }, 10)
+ }
+ again()
+ })
- fs = require('fs-extra');
+ it('should fire the event when the conditions are met and retrieve the expected parameters', function(done) {
+ var ARBITRARY_STRING = 'hello'
+ , ARBITRATY_NUM = 29
+ , processing = 0;
+ var tf = TriggerFlow.create({done: false, processing: processing}, function(someNum, someString) {
+ T (someNum, ARBITRATY_NUM)
+ T (someString, ARBITRARY_STRING)
+ T (tf.hasTriggered)
+ done()
+ })
+ setTimeout(function() { tf.update({done: true }) }, 5)
+
+ function again() {
+ processing += 1;
+ tf.update({processing: processing }, ARBITRATY_NUM, ARBITRARY_STRING)
+ setTimeout(function() {
+ processing -= 1;
+ tf.update({ processing: processing}, ARBITRATY_NUM, ARBITRARY_STRING);
+ }, 10);
+ };
+ again()
+ })
- path = require('path-extra');
+ it('should count down and fire the event when the conditions are met', function(done) {
+ var counter = 10
+ var tf = TriggerFlow.create({counter: counter}, function() {
+ T (counter === 0)
+ clearInterval(decrementer);
+ T (tf.hasTriggered);
+ done();
+ })
+
+ var decrementer = setInterval(function() {
+ counter -= 1;
+ tf.update({counter: counter })
+ }, 5)
+ })
+
+ it('should automatically count down if the number is negative and then fire the event when the conditions are met', function(done) {
+ var tf = trigger({counter: 10}, function() {
+ T (tf.object.counter === 0)
+ clearInterval(decrementer)
+ T (tf.hasTriggered)
+ done()
+ })
+
+ var decrementer = setInterval(function() {
+ tf.update({counter: -1 })
+ }, 5)
+ })
+})
- describe('TriggerFlow', function() {
- it('should fire the event when the conditions are met', function(done) {
- var again, processing, tf;
- processing = 0;
- tf = TriggerFlow.create({
- done: false,
- processing: processing
- }, function() {
- T(tf.hasTriggered);
- return done();
- });
- setTimeout(function() {
- return tf.update({
- done: true
- });
- }, 5);
- again = function() {
- processing += 1;
- tf.update({
- processing: processing
- });
- return setTimeout(function() {
- processing -= 1;
- return tf.update({
- processing: processing
- });
- }, 10);
- };
- return again();
- });
- it('should fire the event when the conditions are met and retrieve the expected parameters', function(done) {
- var ARBITRARY_STRING, ARBITRATY_NUM, again, processing, tf;
- ARBITRARY_STRING = 'hello';
- ARBITRATY_NUM = 29;
- processing = 0;
- tf = TriggerFlow.create({
- done: false,
- processing: processing
- }, function(someNum, someString) {
- T(someNum === ARBITRATY_NUM);
- T(someString === ARBITRARY_STRING);
- T(tf.hasTriggered);
- return done();
- });
- setTimeout(function() {
- return tf.update({
- done: true
- });
- }, 5);
- again = function() {
- processing += 1;
- tf.update({
- processing: processing
- }, ARBITRATY_NUM, ARBITRARY_STRING);
- return setTimeout(function() {
- processing -= 1;
- return tf.update({
- processing: processing
- }, ARBITRATY_NUM, ARBITRARY_STRING);
- }, 10);
- };
- return again();
- });
- it('should count down and fire the event when the conditions are met', function(done) {
- var counter, decrementer, tf;
- counter = 10;
- tf = TriggerFlow.create({
- counter: counter
- }, function() {
- T(counter === 0);
- clearInterval(decrementer);
- T(tf.hasTriggered);
- return done();
- });
- return decrementer = setInterval(function() {
- counter -= 1;
- return tf.update({
- counter: counter
- });
- }, 5);
- });
- return it('should automatically count down if the number is negative and then fire the event when the conditions are met', function(done) {
- var decrementer, tf;
- tf = TriggerFlow.create({
- counter: 10
- }, function() {
- T(tf.object.counter === 0);
- clearInterval(decrementer);
- T(tf.hasTriggered);
- return done();
- });
- return decrementer = setInterval(function() {
- return tf.update({
- counter: -1
- });
- }, 5);
- });
- });
-}).call(this);

0 comments on commit aa7f9da

Please sign in to comment.