You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/05/16 17:57:14 UTC

[15/20] git commit: added tests for action-stack

added tests for action-stack


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/62492ab3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/62492ab3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/62492ab3

Branch: refs/heads/master
Commit: 62492ab39d112d6b9392c3f046c7c023c55879d4
Parents: a77bfcc
Author: Fil Maj <ma...@gmail.com>
Authored: Wed May 15 18:06:09 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu May 16 08:55:43 2013 -0700

----------------------------------------------------------------------
 spec/util/action-stack.spec.js |   52 +++++++++++++++++++++++++++++++++++
 src/util/action-stack.js       |    2 +-
 2 files changed, 53 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/62492ab3/spec/util/action-stack.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/action-stack.spec.js b/spec/util/action-stack.spec.js
new file mode 100644
index 0000000..b258a32
--- /dev/null
+++ b/spec/util/action-stack.spec.js
@@ -0,0 +1,52 @@
+var action_stack = require('../../src/util/action-stack'),
+    ios = require('../../src/platforms/ios');
+
+describe('action-stack', function() {
+    var stack;
+    beforeEach(function() {
+        stack = new action_stack();
+    });
+    describe('processing of actions', function() {
+        it('should process actions one at a time until all are done', function() {
+            var first_spy = jasmine.createSpy();
+            var first_args = [1];
+            var second_spy = jasmine.createSpy();
+            var second_args = [2];
+            var third_spy = jasmine.createSpy();
+            var third_args = [3];
+            stack.push(stack.createAction(first_spy, first_args, function(){}, []));
+            stack.push(stack.createAction(second_spy, second_args, function(){}, []));
+            stack.push(stack.createAction(third_spy, third_args, function(){}, []));
+            stack.process('android', 'blah');
+            expect(first_spy).toHaveBeenCalledWith(first_args[0]);
+            expect(second_spy).toHaveBeenCalledWith(second_args[0]);
+            expect(third_spy).toHaveBeenCalledWith(third_args[0]);
+        });
+        it('should revert processed actions if an exception occurs', function() {
+            var first_spy = jasmine.createSpy();
+            var first_args = [1];
+            var first_reverter = jasmine.createSpy();
+            var first_reverter_args = [true];
+            var process_err = 'quit peein\' on my rug, man.';
+            var second_spy = jasmine.createSpy().andCallFake(function() {
+                throw new Error(process_err);
+            });
+            var second_args = [2];
+            var third_spy = jasmine.createSpy();
+            var third_args = [3];
+            stack.push(stack.createAction(first_spy, first_args, first_reverter, first_reverter_args));
+            stack.push(stack.createAction(second_spy, second_args, function(){}, []));
+            stack.push(stack.createAction(third_spy, third_args, function(){}, []));
+            // process should throw
+            expect(function() {
+                stack.process('android', 'blah');
+            }).toThrow('Uh oh!\n' + process_err);
+            // first two actions should have been called, but not the third
+            expect(first_spy).toHaveBeenCalledWith(first_args[0]);
+            expect(second_spy).toHaveBeenCalledWith(second_args[0]);
+            expect(third_spy).not.toHaveBeenCalledWith(third_args[0]);
+            // first reverter should have been called after second action exploded
+            expect(first_reverter).toHaveBeenCalledWith(first_reverter_args[0]);
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/62492ab3/src/util/action-stack.js
----------------------------------------------------------------------
diff --git a/src/util/action-stack.js b/src/util/action-stack.js
index 115c6b7..886ff21 100644
--- a/src/util/action-stack.js
+++ b/src/util/action-stack.js
@@ -24,7 +24,7 @@ ActionStack.prototype = {
     },
     process:function(platform, project_dir, callback) {
         if (platform == 'ios') {
-            // parse xcode project file once
+            // parse xcode project files once
             var project_files = ios.parseIOSProjectFiles(project_dir);
         }
         while(this.stack.length) {