cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [3/3] git commit: Fixing up ios uninstall tests
Date Mon, 29 Apr 2013 22:52:23 GMT
Fixing up ios uninstall tests


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

Branch: refs/heads/master
Commit: eb4fecc1cf09fd8533ad0caab4748134f6712fcc
Parents: 858a5c4
Author: Tim Kim <timk@adobe.com>
Authored: Thu Apr 25 17:29:31 2013 -0700
Committer: Tim Kim <timk@adobe.com>
Committed: Mon Apr 29 15:51:59 2013 -0700

----------------------------------------------------------------------
 spec/platforms/ios.spec.js |   87 ++++++++++++++++++++++++++++++++++-----
 src/platforms/ios.js       |    9 ++--
 2 files changed, 81 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/eb4fecc1/spec/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/ios.spec.js b/spec/platforms/ios.spec.js
index cb5521f..0b46d1c 100644
--- a/spec/platforms/ios.spec.js
+++ b/spec/platforms/ios.spec.js
@@ -356,16 +356,83 @@ describe('ios project handler', function() {
         });
 
         describe('of <source-file> elements', function() {
-            it('should call into xcodeproj\'s removeSourceFile appropriately when element
has no target-dir');
-            it('should call into xcodeproj\'s removeSourceFile appropriately when element
a no target-dir');
-            it('should rm the file from the right target location when element has a target-dir');
-            it('should rm the file from the right target location when element has no target-dir');
+            it('should call into xcodeproj\'s removeSourceFile appropriately when element
has no target-dir', function(){
+                var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir']
== undefined});
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var spy = jasmine.createSpy();
+                spyOn(xcode, 'project').andReturn({
+                    parseSync:function(){},
+                    writeSync:function(){},
+                    removeSourceFile:spy
+                });
+                
+                ios.uninstall(source, dummy_id, temp, dummyplugin);
+                expect(spy).toHaveBeenCalledWith(path.join('Plugins', 'DummyPluginCommand.m'));
+            });
+            it('should call into xcodeproj\'s removeSourceFile appropriately when element
a target-dir', function(){
+                var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir']
!= undefined});
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var spy = jasmine.createSpy();
+                spyOn(xcode, 'project').andReturn({
+                    parseSync:function(){},
+                    writeSync:function(){},
+                    removeSourceFile:function(){}
+                });
+                
+                var spy = spyOn(shell, 'rm');
+                ios.uninstall(source, dummy_id, temp, dummyplugin);
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
'targetDir', 'TargetDirTest.m'));
+            });
+            it('should rm the file from the right target location when element has no target-dir',
function(){
+                var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir']
== undefined});
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var spy = jasmine.createSpy();
+                spyOn(xcode, 'project').andReturn({
+                    parseSync:function(){},
+                    writeSync:function(){},
+                    removeSourceFile:function(){}
+                });
+                
+                var spy = spyOn(shell, 'rm');
+                ios.uninstall(source, dummy_id, temp, dummyplugin);
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
'DummyPluginCommand.m'));
+            });
+            it('should rm the file from the right target location when element has a target-dir',
function(){
+                var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir']
!= undefined});
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var spy = jasmine.createSpy();
+                spyOn(xcode, 'project').andReturn({
+                    parseSync:function(){},
+                    writeSync:function(){},
+                    removeSourceFile:function(){}
+                });
+                
+                var spy = spyOn(shell, 'rm');
+                ios.uninstall(source, dummy_id, temp, dummyplugin);
+                expect(spy).toHaveBeenCalledWith('-rf', path.join(temp, 'SampleApp', 'Plugins',
'targetDir', 'TargetDirTest.m'));
+            });
         });
 
         describe('of <plugins-plist> elements', function() {
-            it('should only be used in an applicably old cordova-ios project');
-            it('should not be used in an applicably old cordova-ios project');
+            it('should only be used in an applicably old cordova-ios project', function(){
+                shell.cp('-rf', ios_plist_project, temp);
+                var pls = copyArray(plist_els);
+                var spy = spyOn(plist, 'parseFileSync').andReturn({Plugins:{}});
+                ios.uninstall(pls, dummy_id, temp, dummyplugin);
+                expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'PhoneGap.plist'));
+            });
+            it('should not be used in an applicably old cordova-ios project', function()
{
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var pls = copyArray(plist_els);
+                var spy = spyOn(plist, 'parseFileSync').andReturn({Plugins:{}});
+                ios.uninstall(pls, dummy_id, temp, dummyplugin);
+                expect(spy).not.toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'config.xml'));
+            });
             it('should remove the <plugin> element in applicably new cordova-ios projects
with old-style plugins using only <plugins-plist> elements', function() {
+                shell.cp('-rf', ios_config_xml_project, temp);
+                var pls = copyArray(plist_only_els);
+                ios.uninstall(pls, plist_id, temp, plistplugin);
+                expect(fs.readFileSync(path.join(temp, 'SampleApp', 'config.xml'), 'utf-8')).toMatch(/<plugin
name="OldSkewl"/gi);
             });
         });
 
@@ -377,12 +444,10 @@ describe('ios project handler', function() {
         });
 
         describe('of <asset> elements', function() {
-            it('should call rm on specified asset', function() {
-                
-            });
-            it('should call rm on the www/plugins/<plugin_id> folder', function() {
-                
+            it('should call rm on specified asset',function(){
+            
             });
+            it('should call rm on the www/plugins/<plugin_id> folder');
         });
 
         describe('of <header-file> elements', function() {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/eb4fecc1/src/platforms/ios.js
----------------------------------------------------------------------
diff --git a/src/platforms/ios.js b/src/platforms/ios.js
index 70bc539..453e87d 100644
--- a/src/platforms/ios.js
+++ b/src/platforms/ios.js
@@ -98,7 +98,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
                     var srcFile = path.resolve(plugin_dir, src);
                     var targetDir = path.resolve(pluginsDir, getRelativeDir(mod));
                     var destFile = path.resolve(targetDir, path.basename(src));
-                     
                     if (action == 'install') {
                         if (!fs.existsSync(srcFile)) throw new Error('cannot find "' + srcFile
+ '" ios <source-file>');
                         if (fs.existsSync(destFile)) throw new Error('target destination
"' + destFile + '" already exists');
@@ -106,10 +105,12 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         shell.mkdir('-p', targetDir);
                         shell.cp(srcFile, destFile);
                     } else {
-                        xcodeproj.removeSourceFile(path.join('Plugins', path.basename(src)));
+                        xcodeproj.removeSourceFile(path.join('Plugins', path.relative(pluginsDir,
destFile)));
                         shell.rm('-rf', destFile);
-                        // TODO: is this right, should we check if dir is empty?
-                        shell.rm('-rf', targetDir);    
+                        
+                        if(fs.existsSync(targetDir) && fs.readdirSync(targetDir).length>0){
+                            shell.rm('-rf', targetDir); 
+                        }
                     }
                     break;
                 case 'asset':


Mime
View raw message