Permalink
Browse files

uninstall existing apks rather than trying to reinstall

  • Loading branch information...
leviwilson committed Jan 11, 2014
1 parent 1257f84 commit f4055a5a568cfeaaec12745261a8b6a2aac240ce
Showing with 27 additions and 8 deletions.
  1. +16 −5 lib/brazenhead/builder.rb
  2. +11 −3 spec/lib/brazenhead/builder_spec.rb
View
@@ -29,21 +29,28 @@ def install_server(dir)
copy_base_files
update_test_manifest
sign test_apk, @keystore
- reinstall test_apk
- reinstall @source_apk
+ reinstall the_test_target, test_apk
+ reinstall the_target, @source_apk
end
end
- def reinstall(apk, timeout=90)
+ def reinstall(package, apk, timeout=90)
begin
- install apk, "-r", {}, timeout
+ remove package, timeout
+ install apk, nil, {}, timeout
rescue ADB::ADBError => e
$stdout.puts last_stdout
$stderr.puts last_stderr
raise e
end
end
+ def remove(package, timeout)
+ uninstall package, {}, timeout
+ rescue ADB::ADBError
+ # may not be there
+ end
+
def copy_base_files
[test_apk, android_manifest].each do |file|
FileUtils.cp driver_path_for(file), Dir.pwd
@@ -56,7 +63,7 @@ def driver_path_for(file)
def update_test_manifest
replace android_manifest, /\btargetPackage="[^"]+"/, "targetPackage=\"#{the_target}\""
- replace android_manifest, /\bpackage="[^"]+"/, "package=\"#{the_target}.brazenhead\""
+ replace android_manifest, /\bpackage="[^"]+"/, "package=\"#{the_test_target}\""
update_manifest test_apk, android_manifest, manifest_info.target_sdk
end
@@ -68,6 +75,10 @@ def the_target
@the_target ||= manifest_info.package
end
+ def the_test_target
+ "#{the_target}.brazenhead"
+ end
+
def manifest_info
@info ||= Brazenhead::ManifestInfo.new(@source_apk)
end
@@ -23,8 +23,9 @@
FileUtils.stub(:cp)
File.stub(:read).and_return('')
File.stub(:write)
- stub_all server, :update_manifest, :sign, :install
+ stub_all server, :update_manifest, :sign, :install, :uninstall
+ manifest_info.stub(:package).and_return('com.test.package')
Brazenhead::ManifestInfo.stub(:new).with(expanded_apk).and_return(manifest_info)
Brazenhead::Process.stub(:new).and_return(process)
end
@@ -112,15 +113,22 @@ def stub_all(type, *methods)
context "installing the test server" do
it "should reinstall the test server to the device" do
- server.should_receive(:install).with("#{driver_apk}", "-r", {}, 90)
+ server.should_receive(:uninstall).with('com.test.package.brazenhead', {}, 90)
+ server.should_receive(:install).with(driver_apk, nil, {}, 90)
server.build_for(apk, keystore)
end
it "should reinstall the target package to the device" do
- server.should_receive(:install).with(expanded_apk, "-r", {}, 90)
+ server.should_receive(:uninstall).with('com.test.package', {}, 90)
+ server.should_receive(:install).with(expanded_apk, nil, {}, 90)
server.build_for(apk, keystore)
end
+ it 'silently fails if the package is not already there' do
+ server.should_receive(:uninstall).and_raise ADB::ADBError
+ expect { server.build_for(apk, keystore) }.to_not raise_error ADB::ADBError
+ end
+
end
end

0 comments on commit f4055a5

Please sign in to comment.