Quellcode durchsuchen

EAGLESIX-2651: fix up test cases for new code

Kyle P Davis vor 11 Jahren
Ursprung
Commit
1c14539504
1 geänderte Dateien mit 61 neuen und 71 gelöschten Zeilen
  1. 61 71
      test/lib/pipeline/accumulators/AddToSetAccumulator.js

+ 61 - 71
test/lib/pipeline/accumulators/AddToSetAccumulator.js

@@ -2,95 +2,85 @@
 var assert = require("assert"),
 	AddToSetAccumulator = require("../../../../lib/pipeline/accumulators/AddToSetAccumulator");
 
-
-var createAccumulator = function createAccumulator() {
-	return new AddToSetAccumulator();
-};
+// Mocha one-liner to make these tests self-hosted
+if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
 
 //TODO: refactor these test cases using Expression.parseOperand() or something because these could be a whole lot cleaner...
-module.exports = {
+exports.AddToSetAccumulator = {
 
-	"AddToSetAccumulator": {
+	".constructor()": {
+
+		"should create instance of Accumulator": function testCtorAssignsSet() {
+			assert(AddToSetAccumulator.create() instanceof AddToSetAccumulator);
+		},
 
-		"constructor()": {
+		"should error if called with args": function testArgsGivenToCtor() {
+			assert.throws(function() {
+				new AddToSetAccumulator(123);
+			});
+		}
 
-			"should error if called with args": function testArgsGivenToCtor() {
-				assert.throws(function() {
-					new AddToSetAccumulator('arg');
-				});
-			},
+	},
 
-			"should construct object with set property": function testCtorAssignsSet() {
-				var acc = new AddToSetAccumulator();
-				assert.notEqual(acc.set, null);
-				assert.notEqual(acc.set, undefined);
-			}
+	".create()": {
 
-		},
+		"should return an instance of the accumulator": function testCreate() {
+			assert(AddToSetAccumulator.create() instanceof AddToSetAccumulator);
+		}
 
-		"#getFactory()": {
+	},
 
-			"should return the constructor for this class": function factoryIsConstructor(){
-				assert.strictEqual(new AddToSetAccumulator().getFactory(), AddToSetAccumulator);
-			}
+	"#processInternal()": {
 
+		"should add input to set": function testAddsToSet() {
+			var acc = AddToSetAccumulator.create();
+			acc.processInternal(5);
+			var value = acc.getValue();
+			assert.deepEqual(JSON.stringify(value), JSON.stringify([5]));
+		}
+
+	},
+
+	"#getValue()": {
+
+		"should return empty array": function testEmptySet() {
+			var acc = new AddToSetAccumulator.create();
+			var value = acc.getValue();
+			assert.equal((value instanceof Array), true);
+			assert.equal(value.length, 0);
 		},
 
-		"#processInternal()" : {
-			"should add input to set": function testAddsToSet() {
-				var acc = createAccumulator();
-				acc.processInternal(5);
-				var value = acc.getValue();
-				assert.deepEqual(JSON.stringify(value), JSON.stringify([5]));
-			}
+		"should return array with one element that equals 5": function test5InSet() {
+			var acc = AddToSetAccumulator.create();
+			acc.processInternal(5);
+			acc.processInternal(5);
+			var value = acc.getValue();
+			assert.deepEqual(JSON.stringify(value), JSON.stringify([5]));
+		},
 
+		"should produce value that is an array of multiple elements": function testMultipleItems() {
+			var acc = AddToSetAccumulator.create();
+			acc.processInternal(5);
+			acc.processInternal({key: "value"});
+			var value = acc.getValue();
+			assert.deepEqual(JSON.stringify(value), JSON.stringify([5, {key: "value"}]));
 		},
 
-		"#getValue()": {
-
-			"should return empty array": function testEmptySet() {
-				var acc = new createAccumulator();
-				var value = acc.getValue();
-				assert.equal((value instanceof Array), true);
-				assert.equal(value.length, 0);
-			},
-
-			"should return array with one element that equals 5": function test5InSet() {
-				var acc = createAccumulator();
-				acc.processInternal(5);
-				acc.processInternal(5);
-				var value = acc.getValue();
-				assert.deepEqual(JSON.stringify(value), JSON.stringify([5]));
-			},
-
-			"should produce value that is an array of multiple elements": function testMultipleItems() {
-				var acc = createAccumulator();
-				acc.processInternal(5);
-				acc.processInternal({key: "value"});
-				var value = acc.getValue();
-				assert.deepEqual(JSON.stringify(value), JSON.stringify([5, {key: "value"}]));
-			},
-
-			"should return array with one element that is an object containing a key/value pair": function testKeyValue() {
-				var acc = createAccumulator();
-				acc.processInternal({key: "value"});
-				var value = acc.getValue();
-				assert.deepEqual(JSON.stringify(value), JSON.stringify([{key: "value"}]));
-			},
-
-			"should coalesce different instances of equivalent objects": function testGetValue_() {
-				var acc = createAccumulator();
-				acc.processInternal({key: "value"});
-				acc.processInternal({key: "value"});
-				var value = acc.getValue();
-				assert.deepEqual(JSON.stringify(value), JSON.stringify([{key: "value"}]));
-			}
+		"should return array with one element that is an object containing a key/value pair": function testKeyValue() {
+			var acc = AddToSetAccumulator.create();
+			acc.processInternal({key: "value"});
+			var value = acc.getValue();
+			assert.deepEqual(JSON.stringify(value), JSON.stringify([{key: "value"}]));
+		},
 
+		"should coalesce different instances of equivalent objects": function testGetValue_() {
+			var acc = AddToSetAccumulator.create();
+			acc.processInternal({key: "value"});
+			acc.processInternal({key: "value"});
+			var value = acc.getValue();
+			assert.deepEqual(JSON.stringify(value), JSON.stringify([{key: "value"}]));
 		}
 
 	}
 
 };
-
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);