| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::CLI::Zap, :cask do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   it "shows an error when a bad Cask is provided" do | 
					
						
							| 
									
										
										
										
											2017-06-13 17:14:01 +02:00
										 |  |  |     expect { Hbc::CLI::Zap.run("notacask") } | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |       .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "can zap and unlink multiple Casks at once" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |     caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") | 
					
						
							|  |  |  |     transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     Hbc::Installer.new(caffeine).install | 
					
						
							|  |  |  |     Hbc::Installer.new(transmission).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:44:28 +01:00
										 |  |  |     expect(caffeine).to be_installed | 
					
						
							|  |  |  |     expect(transmission).to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     Hbc::CLI::Zap.run("local-caffeine", "local-transmission") | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:44:28 +01:00
										 |  |  |     expect(caffeine).not_to be_installed | 
					
						
							|  |  |  |     expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink | 
					
						
							|  |  |  |     expect(transmission).not_to be_installed | 
					
						
							|  |  |  |     expect(Hbc.appdir.join("Transmission.app")).not_to be_a_symlink | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # TODO: Explicit test that both zap and uninstall directives get dispatched. | 
					
						
							|  |  |  |   #       The above tests that implicitly. | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # it "dispatches both uninstall and zap stanzas" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |   #   with_zap = Hbc::CaskLoader.load('with-zap') | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   # | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |   #   Hbc::Installer.new(with_zap).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   # | 
					
						
							|  |  |  |   #   with_zap.must_be :installed? | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app.from.uninstall"'], '1') | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app.from.uninstall" to quit']) | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', with_zap.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) | 
					
						
							|  |  |  |   #   Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', | 
					
						
							|  |  |  |   #                                             Pathname.new('~/Library/Preferences/my.fancy.app.plist').expand_path]) | 
					
						
							|  |  |  |   # | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |   #   Hbc::CLI::Zap.run('with-zap') | 
					
						
							|  |  |  |   # | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   #   with_zap.wont_be :installed? | 
					
						
							|  |  |  |   # end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "when no Cask is specified" do | 
					
						
							|  |  |  |     it "raises an exception" do | 
					
						
							| 
									
										
										
										
											2017-02-08 13:44:28 +01:00
										 |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         Hbc::CLI::Zap.run | 
					
						
							| 
									
										
										
										
											2017-02-08 13:44:28 +01:00
										 |  |  |       }.to raise_error(Hbc::CaskUnspecifiedError) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "when no Cask is specified, but an invalid option" do | 
					
						
							|  |  |  |     it "raises an exception" do | 
					
						
							| 
									
										
										
										
											2017-02-08 13:44:28 +01:00
										 |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         Hbc::CLI::Zap.run("--notavalidoption") | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       }.to raise_error(/invalid option/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |