brew/Library/Homebrew/test/cask/depends_on_spec.rb

110 lines
3.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-02-08 08:30:33 +01:00
# TODO: this test should be named after the corresponding class, once
# that class is abstracted from installer.rb
2017-03-05 19:26:56 +01:00
describe "Satisfy Dependencies and Requirements", :cask do
2019-10-03 08:50:45 +02:00
subject(:install) {
Cask::Installer.new(cask).install
2017-02-08 08:30:33 +01:00
}
describe "depends_on cask" do
let(:dependency) { Cask::CaskLoader.load(cask.depends_on.cask.first) }
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-cask")) }
it "installs the dependency of a Cask and the Cask itself" do
2019-10-03 08:50:45 +02:00
expect { install }.not_to raise_error
expect(cask).to be_installed
expect(dependency).to be_installed
end
2017-02-08 08:30:33 +01:00
context "when depends_on cask is cyclic" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) }
2017-10-03 10:49:58 +02:00
it {
2019-10-03 08:50:45 +02:00
expect { install }.to raise_error(
2018-09-06 08:29:14 +02:00
Cask::CaskCyclicDependencyError,
"Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies "\
"on other Casks: with-depends-on-cask-cyclic-helper",
)
2017-10-03 10:49:58 +02:00
}
2017-02-08 08:30:33 +01:00
end
end
describe "depends_on macos" do
context "given an array" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-macos-array")) }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
2017-09-10 16:30:30 +00:00
context "given a comparison" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-macos-comparison")) }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
context "given a symbol" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-macos-symbol")) }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
context "when not satisfied" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-macos-failure")) }
2019-10-03 08:50:45 +02:00
it "raises an error" do
expect { install }.to raise_error(Cask::CaskError)
end
2017-02-08 08:30:33 +01:00
end
end
describe "depends_on arch" do
context "when satisfied" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-arch")) }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
end
describe "depends_on x11" do
before do
2017-02-08 08:30:33 +01:00
allow(MacOS::X11).to receive(:installed?).and_return(x11_installed)
end
context "when satisfied" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11")) }
2017-02-08 08:30:33 +01:00
let(:x11_installed) { true }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
context "when not satisfied" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11")) }
2017-02-08 08:30:33 +01:00
let(:x11_installed) { false }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.to raise_error Cask::CaskX11DependencyError
end
2017-02-08 08:30:33 +01:00
end
context "when depends_on x11: false" do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11-false")) }
2017-02-08 08:30:33 +01:00
let(:x11_installed) { false }
2019-10-03 08:50:45 +02:00
it "does not raise an error" do
expect { install }.not_to raise_error
end
2017-02-08 08:30:33 +01:00
end
end
end