add initial tests
This commit is contained in:
parent
836efe621f
commit
e8e6ee30b4
@ -95,7 +95,7 @@ module Cask
|
||||
|
||||
# if launchctl item contains a wildcard, find matching process(es)
|
||||
services.each do |service|
|
||||
all_services << service
|
||||
all_services << service unless service.include?("*")
|
||||
next unless service.include?("*")
|
||||
|
||||
all_services += find_launchctl_with_wildcard(service)
|
||||
|
||||
@ -61,6 +61,19 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
||||
end
|
||||
end
|
||||
|
||||
context "using launchctl with regex" do
|
||||
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-launchctl-wildcard")) }
|
||||
let(:launchctl_list_cmd) { %w[/bin/launchctl list] }
|
||||
|
||||
it "searches running launchctl items" do
|
||||
allow(fake_system_command).to receive(:run)
|
||||
.with("/bin/launchctl", args: ["list"], print_stderr: false, sudo: false)
|
||||
.and_return(instance_double(SystemCommand::Result))
|
||||
|
||||
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
|
||||
end
|
||||
end
|
||||
|
||||
context "using :pkgutil" do
|
||||
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-pkgutil")) }
|
||||
|
||||
@ -117,9 +130,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
||||
allow(User.current).to receive(:gui?).and_return false
|
||||
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
|
||||
|
||||
expect {
|
||||
expect do
|
||||
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
|
||||
}.to output(/Not logged into a GUI; skipping quitting application ID 'my.fancy.package.app'\./).to_stderr
|
||||
end.to output(/Not logged into a GUI; skipping quitting application ID 'my.fancy.package.app'\./).to_stderr
|
||||
end
|
||||
|
||||
it "quits a running application" do
|
||||
@ -130,9 +143,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
||||
.and_return(instance_double("SystemCommand::Result", success?: true))
|
||||
expect(subject).to receive(:running?).with(bundle_id).ordered.and_return(false)
|
||||
|
||||
expect {
|
||||
expect do
|
||||
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
|
||||
}.to output(/Application 'my.fancy.package.app' quit successfully\./).to_stdout
|
||||
end.to output(/Application 'my.fancy.package.app' quit successfully\./).to_stdout
|
||||
end
|
||||
|
||||
it "tries to quit the application for 10 seconds" do
|
||||
@ -143,9 +156,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
||||
.and_return(instance_double("SystemCommand::Result", success?: false))
|
||||
|
||||
time = Benchmark.measure do
|
||||
expect {
|
||||
expect do
|
||||
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
|
||||
}.to output(/Application 'my.fancy.package.app' did not quit\./).to_stderr
|
||||
end.to output(/Application 'my.fancy.package.app' did not quit\./).to_stderr
|
||||
end
|
||||
|
||||
expect(time.real).to be_within(3).of(10)
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
cask "with-uninstall-launchctl-wildcard" do
|
||||
version "1.2.3"
|
||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||
|
||||
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
|
||||
homepage "https://brew.sh/fancy"
|
||||
|
||||
app "Fancy.app"
|
||||
|
||||
uninstall launchctl: "my.fancy.package.service.*"
|
||||
end
|
||||
@ -0,0 +1,11 @@
|
||||
cask "with-zap-launchctl-wildcard" do
|
||||
version "1.2.3"
|
||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||
|
||||
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
|
||||
homepage "https://brew.sh/fancy"
|
||||
|
||||
app "Fancy.app"
|
||||
|
||||
zap launchctl: "my.fancy.package.service.*"
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user