| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::Artifact::Uninstall, :cask do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |   let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let(:uninstall_artifact) { | 
					
						
							|  |  |  |     Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:48 +01:00
										 |  |  |   let(:dir) { TEST_TMPDIR } | 
					
						
							|  |  |  |   let(:absolute_path) { Pathname.new("#{dir}/absolute_path") } | 
					
						
							|  |  |  |   let(:path_with_tilde) { Pathname.new("#{dir}/path_with_tilde") } | 
					
						
							|  |  |  |   let(:glob_path1) { Pathname.new("#{dir}/glob_path1") } | 
					
						
							|  |  |  |   let(:glob_path2) { Pathname.new("#{dir}/glob_path2") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   around(:each) do |example| | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       ENV["HOME"] = dir | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       paths = [ | 
					
						
							|  |  |  |         absolute_path, | 
					
						
							|  |  |  |         path_with_tilde, | 
					
						
							|  |  |  |         glob_path1, | 
					
						
							|  |  |  |         glob_path2, | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       FileUtils.touch paths | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         InstallHelper.install_without_artifacts(cask) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       example.run | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       FileUtils.rm_f paths | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "uninstall_phase" do | 
					
						
							| 
									
										
										
										
											2017-02-05 07:47:54 +01:00
										 |  |  |     subject { | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       shutup do | 
					
						
							|  |  |  |         uninstall_artifact.uninstall_phase | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-02-05 07:47:54 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using launchctl" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-launchctl.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } | 
					
						
							|  |  |  |       let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } | 
					
						
							|  |  |  |       let(:unknown_response) { "launchctl list returned unknown response\n" } | 
					
						
							|  |  |  |       let(:service_info) { | 
					
						
							| 
									
										
										
										
											2016-08-24 13:23:27 +02:00
										 |  |  |         <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           { | 
					
						
							|  |  |  |                   "LimitLoadToSessionType" = "Aqua"; | 
					
						
							|  |  |  |                   "Label" = "my.fancy.package.service"; | 
					
						
							|  |  |  |                   "TimeOut" = 30; | 
					
						
							|  |  |  |                   "OnDemand" = true; | 
					
						
							|  |  |  |                   "LastExitStatus" = 0; | 
					
						
							|  |  |  |                   "ProgramArguments" = ( | 
					
						
							|  |  |  |                           "argument"; | 
					
						
							|  |  |  |                   ); | 
					
						
							|  |  |  |           }; | 
					
						
							| 
									
										
										
										
											2016-08-24 13:23:27 +02:00
										 |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |       context "when launchctl job is owned by user" do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         it "can uninstall" do | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             launchctl_list_cmd, | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             service_info, | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             sudo(launchctl_list_cmd), | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             unknown_response, | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           subject | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |       context "when launchctl job is owned by system" do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         it "can uninstall" do | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             launchctl_list_cmd, | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             unknown_response, | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             sudo(launchctl_list_cmd), | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             service_info, | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           subject | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using pkgutil" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-pkgutil.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:main_pkg_id) { "my.fancy.package.main" } | 
					
						
							|  |  |  |       let(:agent_pkg_id) { "my.fancy.package.agent" } | 
					
						
							|  |  |  |       let(:main_files) { | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           fancy/bin/fancy.exe | 
					
						
							|  |  |  |           fancy/var/fancy.data | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       let(:main_dirs) { | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           fancy | 
					
						
							|  |  |  |           fancy/bin | 
					
						
							|  |  |  |           fancy/var | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       let(:agent_files) { | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           fancy/agent/fancy-agent.exe | 
					
						
							|  |  |  |           fancy/agent/fancy-agent.pid | 
					
						
							|  |  |  |           fancy/agent/fancy-agent.log | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       let(:agent_dirs) { | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           fancy | 
					
						
							|  |  |  |           fancy/agent | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       let(:pkg_info_plist) { | 
					
						
							| 
									
										
										
										
											2016-08-24 13:23:27 +02:00
										 |  |  |         <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           <?xml version="1.0" encoding="UTF-8"?> | 
					
						
							|  |  |  |           <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | 
					
						
							|  |  |  |           <plist version="1.0"> | 
					
						
							|  |  |  |           <dict> | 
					
						
							|  |  |  |                   <key>install-location</key>
 | 
					
						
							|  |  |  |                   <string>tmp</string>
 | 
					
						
							|  |  |  |                   <key>volume</key>
 | 
					
						
							|  |  |  |                   <string>/</string> | 
					
						
							|  |  |  |           </dict>
 | 
					
						
							|  |  |  |           </plist>
 | 
					
						
							| 
									
										
										
										
											2016-08-24 13:23:27 +02:00
										 |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |           %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           "#{main_pkg_id}\n#{agent_pkg_id}", | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           [main_pkg_id, main_files, main_dirs], | 
					
						
							|  |  |  |           [agent_pkg_id, agent_files, agent_dirs], | 
					
						
							|  |  |  |         ].each do |pkg_id, pkg_files, pkg_dirs| | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             pkg_files.join("\n"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             pkg_dirs.join("\n"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             %W[/usr/sbin/pkgutil --files #{pkg_id}], | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             (pkg_files + pkg_dirs).join("\n"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |             %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             pkg_info_plist, | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |             sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}") }), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           ) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using kext" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-kext.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:kext_id) { "my.fancy.package.kernelextension" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.stubs_command( | 
					
						
							|  |  |  |           sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), "loaded" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           sudo(%W[/sbin/kextunload -b #{kext_id}]), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2016-11-18 22:53:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							|  |  |  |           sudo(%W[/usr/sbin/kextfind -b #{kext_id}]), "/Library/Extensions/FancyPackage.kext\n" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           sudo(["/bin/rm", "-rf", "/Library/Extensions/FancyPackage.kext"]), | 
					
						
							| 
									
										
										
										
											2016-11-18 22:53:25 +01:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using quit" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-quit.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:bundle_id) { "my.fancy.package.app" } | 
					
						
							|  |  |  |       let(:quit_application_script) { | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:05 +02:00
										 |  |  |         %Q(tell application id "#{bundle_id}" to quit) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.stubs_command( | 
					
						
							| 
									
										
										
										
											2016-11-09 09:32:54 +01:00
										 |  |  |           %w[/bin/launchctl list], "999\t0\t#{bundle_id}\n" | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.stubs_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           %w[/bin/launchctl list], | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using signal" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-signal.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:bundle_id) { "my.fancy.package.app" } | 
					
						
							|  |  |  |       let(:signals) { %w[TERM KILL] } | 
					
						
							|  |  |  |       let(:unix_pids) { [12_345, 67_890] } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.stubs_command( | 
					
						
							| 
									
										
										
										
											2016-11-09 09:32:54 +01:00
										 |  |  |           %w[/bin/launchctl list], unix_pids.map { |pid| [pid, 0, bundle_id].join("\t") }.join("\n") | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         signals.each do |signal| | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |           expect(Process).to receive(:kill).with(signal, *unix_pids) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using delete" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-delete.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							|  |  |  |           sudo(%w[/bin/rm -rf --], | 
					
						
							| 
									
										
										
										
											2017-02-19 07:57:41 +03:00
										 |  |  |                absolute_path, | 
					
						
							|  |  |  |                path_with_tilde, | 
					
						
							|  |  |  |                glob_path1, | 
					
						
							|  |  |  |                glob_path2), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using trash" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-trash.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							|  |  |  |           sudo(%w[/bin/rm -rf --], | 
					
						
							| 
									
										
										
										
											2017-02-19 07:57:41 +03:00
										 |  |  |                absolute_path, | 
					
						
							|  |  |  |                path_with_tilde, | 
					
						
							|  |  |  |                glob_path1, | 
					
						
							|  |  |  |                glob_path2), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using rmdir" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-rmdir.rb") } | 
					
						
							| 
									
										
										
										
											2017-02-19 07:59:57 +03:00
										 |  |  |       let(:empty_directory_path) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before(:each) do | 
					
						
							|  |  |  |         empty_directory_path.mkdir | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       after(:each) do | 
					
						
							|  |  |  |         empty_directory_path.rmdir | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-19 07:59:57 +03:00
										 |  |  |           sudo(%w[/bin/rm -f --], empty_directory_path/".DS_Store"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-19 07:59:57 +03:00
										 |  |  |           sudo(%w[/bin/rmdir --], empty_directory_path), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using script" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using early_script" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-early-script.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |           sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please"), | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 03:29:53 +01:00
										 |  |  |     context "when using login_item" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-login-item.rb") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "can uninstall" do | 
					
						
							|  |  |  |         Hbc::FakeSystemCommand.expects_command( | 
					
						
							|  |  |  |           ["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \ | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |                                        'item whose name is "Fancy"'], | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subject | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |