aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cask_spec.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-05 06:31:36 +0100
committerMarkus Reiter2017-03-05 23:08:14 +0100
commit9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2 (patch)
tree43e99a683329471c1dc965dcc92daccb57df7e8d /Library/Homebrew/test/cask/cask_spec.rb
parent67ec76d1492fbb03959a782a85c4fb985d6a5884 (diff)
downloadbrew-9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2.tar.bz2
Move Cask specs into `brew tests`.
Diffstat (limited to 'Library/Homebrew/test/cask/cask_spec.rb')
-rw-r--r--Library/Homebrew/test/cask/cask_spec.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb
new file mode 100644
index 000000000..d76f2dce9
--- /dev/null
+++ b/Library/Homebrew/test/cask/cask_spec.rb
@@ -0,0 +1,92 @@
+describe Hbc::Cask, :cask do
+ 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
+
+ describe "load" do
+ let(:tap_path) { Hbc.default_tap.path }
+ let(:file_dirname) { Pathname.new(__FILE__).dirname }
+ let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) }
+
+ it "returns an instance of the Cask for the given token" do
+ c = Hbc.load("local-caffeine")
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("local-caffeine")
+ end
+
+ it "returns an instance of the Cask from a specific file location" do
+ c = Hbc.load("#{tap_path}/Casks/local-caffeine.rb")
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("local-caffeine")
+ end
+
+ it "returns an instance of the Cask from a url" do
+ c = shutup do
+ Hbc.load("file://#{tap_path}/Casks/local-caffeine.rb")
+ end
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("local-caffeine")
+ end
+
+ it "raises an error when failing to download a Cask from a url" do
+ expect {
+ url = "file://#{tap_path}/Casks/notacask.rb"
+ shutup do
+ Hbc.load(url)
+ end
+ }.to raise_error(Hbc::CaskUnavailableError)
+ end
+
+ it "returns an instance of the Cask from a relative file location" do
+ c = Hbc.load(relative_tap_path/"Casks/local-caffeine.rb")
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("local-caffeine")
+ end
+
+ it "uses exact match when loading by token" do
+ expect(Hbc.load("test-opera").token).to eq("test-opera")
+ expect(Hbc.load("test-opera-mail").token).to eq("test-opera-mail")
+ end
+
+ it "raises an error when attempting to load a Cask that doesn't exist" do
+ expect {
+ Hbc.load("notacask")
+ }.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
+ cask_token = "local-caffeine"
+ c = Hbc.load(cask_token)
+ metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
+ expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s)
+ end
+ end
+end