2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Artifact::PreflightBlock, :cask do
|
2016-08-18 22:11:42 +03:00
|
|
|
describe "install_phase" do
|
|
|
|
it "calls the specified block before installing, passing a Cask mini-dsl" do
|
2017-02-08 10:09:00 +01:00
|
|
|
called = false
|
2016-08-18 22:11:42 +03:00
|
|
|
yielded_arg = nil
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
cask = Cask::Cask.new("with-preflight") do
|
2016-08-18 22:11:42 +03:00
|
|
|
preflight do |c|
|
|
|
|
called = true
|
|
|
|
yielded_arg = c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-04 17:54:52 +02:00
|
|
|
cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 10:09:00 +01:00
|
|
|
expect(called).to be true
|
2022-09-13 09:43:09 +01:00
|
|
|
expect(yielded_arg).to be_a Cask::DSL::Preflight
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "uninstall_phase" do
|
|
|
|
it "calls the specified block before uninstalling, passing a Cask mini-dsl" do
|
2017-02-08 10:09:00 +01:00
|
|
|
called = false
|
2016-08-18 22:11:42 +03:00
|
|
|
yielded_arg = nil
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
cask = Cask::Cask.new("with-uninstall-preflight") do
|
2016-08-18 22:11:42 +03:00
|
|
|
uninstall_preflight do |c|
|
|
|
|
called = true
|
|
|
|
yielded_arg = c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-04 17:54:52 +02:00
|
|
|
cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.uninstall_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 10:09:00 +01:00
|
|
|
expect(called).to be true
|
2022-09-13 09:43:09 +01:00
|
|
|
expect(yielded_arg).to be_a Cask::DSL::UninstallPreflight
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|