2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::Cask, :cask do
|
2016-08-18 22:11:42 +03:00
|
|
|
let(:cask) { described_class.new("versioned-cask") }
|
|
|
|
|
|
|
|
context "when multiple versions are installed" do
|
|
|
|
describe "#versions" do
|
|
|
|
context "and there are duplicate versions" do
|
|
|
|
it "uses the last unique version" do
|
|
|
|
allow(cask).to receive(:timestamped_versions).and_return([
|
|
|
|
["1.2.2", "0999"],
|
|
|
|
["1.2.3", "1000"],
|
|
|
|
["1.2.2", "1001"],
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(cask).to receive(:timestamped_versions)
|
|
|
|
expect(cask.versions).to eq([
|
|
|
|
"1.2.3",
|
|
|
|
"1.2.2",
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-09 04:15:57 +01:00
|
|
|
|
|
|
|
describe "load" do
|
2017-03-04 21:42:09 +01:00
|
|
|
let(:tap_path) { Hbc.default_tap.path }
|
|
|
|
let(:file_dirname) { Pathname.new(__FILE__).dirname }
|
2017-05-07 13:52:57 +01:00
|
|
|
let(:relative_tap_path) { tap_path.realpath.relative_path_from(file_dirname) }
|
2017-02-09 04:15:57 +01:00
|
|
|
|
|
|
|
it "returns an instance of the Cask for the given token" do
|
2017-03-13 01:09:36 +01:00
|
|
|
c = Hbc::CaskLoader.load("local-caffeine")
|
2017-02-09 04:15:57 +01:00
|
|
|
expect(c).to be_kind_of(Hbc::Cask)
|
2017-03-04 21:42:09 +01:00
|
|
|
expect(c.token).to eq("local-caffeine")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an instance of the Cask from a specific file location" do
|
2017-03-13 01:09:36 +01:00
|
|
|
c = Hbc::CaskLoader.load("#{tap_path}/Casks/local-caffeine.rb")
|
2017-02-09 04:15:57 +01:00
|
|
|
expect(c).to be_kind_of(Hbc::Cask)
|
2017-03-04 21:42:09 +01:00
|
|
|
expect(c.token).to eq("local-caffeine")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an instance of the Cask from a url" do
|
|
|
|
c = shutup do
|
2017-03-13 01:09:36 +01:00
|
|
|
Hbc::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
expect(c).to be_kind_of(Hbc::Cask)
|
2017-03-04 21:42:09 +01:00
|
|
|
expect(c.token).to eq("local-caffeine")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when failing to download a Cask from a url" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
url = "file://#{tap_path}/Casks/notacask.rb"
|
2017-02-09 04:15:57 +01:00
|
|
|
shutup do
|
2017-03-13 01:09:36 +01:00
|
|
|
Hbc::CaskLoader.load(url)
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
}.to raise_error(Hbc::CaskUnavailableError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an instance of the Cask from a relative file location" do
|
2017-05-07 13:52:57 +01:00
|
|
|
c = file_dirname.cd do
|
|
|
|
Hbc::CaskLoader.load(relative_tap_path/"Casks/local-caffeine.rb")
|
|
|
|
end
|
2017-02-09 04:15:57 +01:00
|
|
|
expect(c).to be_kind_of(Hbc::Cask)
|
2017-03-04 21:42:09 +01:00
|
|
|
expect(c.token).to eq("local-caffeine")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses exact match when loading by token" do
|
2017-03-13 01:09:36 +01:00
|
|
|
expect(Hbc::CaskLoader.load("test-opera").token).to eq("test-opera")
|
|
|
|
expect(Hbc::CaskLoader.load("test-opera-mail").token).to eq("test-opera-mail")
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when attempting to load a Cask that doesn't exist" do
|
|
|
|
expect {
|
2017-03-13 01:09:36 +01:00
|
|
|
Hbc::CaskLoader.load("notacask")
|
2017-02-09 04:15:57 +01:00
|
|
|
}.to raise_error(Hbc::CaskUnavailableError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "all_tokens" do
|
|
|
|
it "returns a token for every Cask" do
|
|
|
|
all_cask_tokens = Hbc.all_tokens
|
|
|
|
expect(all_cask_tokens.count).to be > 20
|
|
|
|
all_cask_tokens.each { |token| expect(token).to be_kind_of(String) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "metadata" do
|
|
|
|
it "proposes a versioned metadata directory name for each instance" do
|
2017-03-04 21:42:09 +01:00
|
|
|
cask_token = "local-caffeine"
|
2017-03-13 01:09:36 +01:00
|
|
|
c = Hbc::CaskLoader.load(cask_token)
|
2017-04-20 10:48:32 +02:00
|
|
|
metadata_timestamped_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
|
|
|
|
expect(c.metadata_versioned_path.to_s).to eq(metadata_timestamped_path.to_s)
|
2017-02-09 04:15:57 +01:00
|
|
|
end
|
|
|
|
end
|
2017-02-27 22:33:34 +02:00
|
|
|
|
|
|
|
describe "outdated" do
|
|
|
|
it "ignores the Casks that have auto_updates true (without --greedy)" do
|
2017-03-13 01:09:36 +01:00
|
|
|
c = Hbc::CaskLoader.load("auto-updates")
|
2017-02-27 22:33:34 +02:00
|
|
|
expect(c).not_to be_outdated
|
|
|
|
expect(c.outdated_versions).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores the Casks that have version :latest (without --greedy)" do
|
2017-03-13 01:09:36 +01:00
|
|
|
c = Hbc::CaskLoader.load("version-latest-string")
|
2017-02-27 22:33:34 +02:00
|
|
|
expect(c).not_to be_outdated
|
|
|
|
expect(c.outdated_versions).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "versioned casks" do
|
|
|
|
let(:cask) { described_class.new("basic-cask") }
|
|
|
|
subject { cask.outdated_versions }
|
|
|
|
|
|
|
|
shared_examples "versioned casks" do |tap_version, expectations|
|
|
|
|
expectations.each do |installed_versions, expected_output|
|
|
|
|
context "when versions #{installed_versions.inspect} are installed and the tap version is #{tap_version}" do
|
|
|
|
it {
|
|
|
|
allow(cask).to receive(:versions).and_return(installed_versions)
|
|
|
|
allow(cask).to receive(:version).and_return(Hbc::DSL::Version.new(tap_version))
|
|
|
|
expect(cask).to receive(:outdated_versions).and_call_original
|
|
|
|
is_expected.to eq expected_output
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "installed version is equal to tap version => not outdated" do
|
|
|
|
include_examples "versioned casks", "1.2.3",
|
|
|
|
["1.2.3"] => [],
|
|
|
|
["1.2.4", "1.2.3"] => []
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "installed version is different than tap version => outdated" do
|
|
|
|
include_examples "versioned casks", "1.2.4",
|
|
|
|
["1.2.3"] => ["1.2.3"],
|
|
|
|
["1.2.4", "1.2.3"] => ["1.2.3"],
|
|
|
|
["1.2.2", "1.2.3"] => ["1.2.2", "1.2.3"],
|
|
|
|
["1.2.2", "1.2.4", "1.2.3"] => ["1.2.2", "1.2.3"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ":latest casks" do
|
|
|
|
let(:cask) { described_class.new("basic-cask") }
|
|
|
|
|
|
|
|
shared_examples ":latest cask" do |greedy, tap_version, expectations|
|
|
|
|
expectations.each do |installed_version, expected_output|
|
|
|
|
context "when versions #{installed_version} are installed and the tap version is #{tap_version}, #{greedy ? "" : "not"} greedy" do
|
|
|
|
subject { cask.outdated_versions greedy }
|
|
|
|
it {
|
|
|
|
allow(cask).to receive(:versions).and_return(installed_version)
|
|
|
|
allow(cask).to receive(:version).and_return(Hbc::DSL::Version.new(tap_version))
|
|
|
|
expect(cask).to receive(:outdated_versions).and_call_original
|
|
|
|
is_expected.to eq expected_output
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ":latest version installed, :latest version in tap" do
|
|
|
|
include_examples ":latest cask", false, "latest",
|
|
|
|
["latest"] => []
|
|
|
|
include_examples ":latest cask", true, "latest",
|
|
|
|
["latest"] => ["latest"]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "numbered version installed, :latest version in tap" do
|
|
|
|
include_examples ":latest cask", false, "latest",
|
|
|
|
["1.2.3"] => ["1.2.3"]
|
|
|
|
include_examples ":latest cask", true, "latest",
|
|
|
|
["1.2.3"] => ["1.2.3"]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "latest version installed, numbered version in tap" do
|
|
|
|
include_examples ":latest cask", false, "1.2.3",
|
|
|
|
["latest"] => ["latest"]
|
|
|
|
include_examples ":latest cask", true, "1.2.3",
|
|
|
|
["latest"] => ["latest"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|