Merge pull request #1329 from jawshooah/cask/cleanup-tests
cask/test: DRY up tests and remove redundant helper
This commit is contained in:
commit
5b421b93c9
@ -1,16 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
describe "Casks" do
|
||||
with_environment "HOMEBREW_DEVELOPER" => nil do
|
||||
Hbc.all.reject {|c| c.is_a?(Hbc::TestCask) }.each do |cask|
|
||||
describe "#{cask}" do
|
||||
it "passes audit" do
|
||||
audit = Hbc::Audit.new(cask)
|
||||
audit.run!
|
||||
audit.errors.must_equal [], "[#{cask}] Cask audit must be error free"
|
||||
audit.warnings.must_equal [], "[#{cask}] Cask audit must be warning free"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,85 +1,81 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::Artifact::App do
|
||||
let(:local_alt_caffeine) {
|
||||
Hbc.load("with-alt-target").tap do |cask|
|
||||
describe "activate to alternate target" do
|
||||
let(:cask) { Hbc.load("with-alt-target") }
|
||||
|
||||
let(:install_phase) {
|
||||
lambda { Hbc::Artifact::App.new(cask).install_phase }
|
||||
}
|
||||
|
||||
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
||||
let(:target_path) { Hbc.appdir.join("AnotherName.app") }
|
||||
|
||||
before do
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
}
|
||||
|
||||
describe "activate to alternate target" do
|
||||
it "installs the given apps using the proper target directory" do
|
||||
cask = local_alt_caffeine
|
||||
source_path.must_be :directory?
|
||||
target_path.wont_be :exist?
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("AnotherName.app")).must_equal false
|
||||
target_path.must_be :directory?
|
||||
source_path.wont_be :exist?
|
||||
end
|
||||
|
||||
it "works with an application in a subdir" do
|
||||
subdir_cask = Hbc::Cask.new("subdir") do
|
||||
url TestHelper.local_binary_url("caffeine.zip")
|
||||
homepage "http://example.com/local-caffeine"
|
||||
version "1.2.3"
|
||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||
app "subdir/Caffeine.app", target: "AnotherName.app"
|
||||
end
|
||||
describe "when app is in a subdirectory" do
|
||||
let(:cask) {
|
||||
Hbc::Cask.new("subdir") do
|
||||
url TestHelper.local_binary_url("caffeine.zip")
|
||||
homepage "http://example.com/local-caffeine"
|
||||
version "1.2.3"
|
||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||
app "subdir/Caffeine.app", target: "AnotherName.app"
|
||||
end
|
||||
}
|
||||
|
||||
begin
|
||||
TestHelper.install_without_artifacts(subdir_cask)
|
||||
|
||||
appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath)
|
||||
FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir)
|
||||
it "installs the given apps using the proper target directory" do
|
||||
appsubdir = cask.staged_path.join("subdir").tap(&:mkpath)
|
||||
FileUtils.mv(source_path, appsubdir)
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(subdir_cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory"
|
||||
File.exist?(appsubdir.join("AnotherName.app")).must_equal false
|
||||
ensure
|
||||
if defined?(subdir_cask)
|
||||
shutup do
|
||||
Hbc::Installer.new(subdir_cask).uninstall
|
||||
end
|
||||
end
|
||||
target_path.must_be :directory?
|
||||
appsubdir.join("Caffeine.app").wont_be :exist?
|
||||
end
|
||||
end
|
||||
|
||||
it "only uses apps when they are specified" do
|
||||
cask = local_alt_caffeine
|
||||
|
||||
staged_app_path = cask.staged_path.join("Caffeine.app")
|
||||
staged_app_copy = staged_app_path.sub("Caffeine.app", "Caffeine Deluxe.app")
|
||||
FileUtils.cp_r staged_app_path, staged_app_copy
|
||||
staged_app_copy = source_path.sub("Caffeine.app", "Caffeine Deluxe.app")
|
||||
FileUtils.cp_r source_path, staged_app_copy
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory"
|
||||
File.exist?(staged_app_path).must_equal false
|
||||
target_path.must_be :directory?
|
||||
source_path.wont_be :exist?
|
||||
|
||||
File.exist?(Hbc.appdir.join("AnotherNameAgain.app")).must_equal false
|
||||
File.exist?(cask.staged_path.join("Caffeine Deluxe.app")).must_equal true
|
||||
Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
|
||||
cask.staged_path.join("Caffeine Deluxe.app").must_be :directory?
|
||||
end
|
||||
|
||||
it "avoids clobbering an existing app by moving over it" do
|
||||
cask = local_alt_caffeine
|
||||
target_path.mkpath
|
||||
|
||||
existing_app_path = Hbc.appdir.join("AnotherName.app")
|
||||
existing_app_path.mkpath
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
}, "==> It seems there is already an App at '#{existing_app_path}'; not moving.")
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
|
||||
File.identical?(source_path, existing_app_path).must_equal false
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
File.identical?(source_path, target_path).must_equal false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,113 +1,95 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::Artifact::App do
|
||||
let(:local_caffeine) {
|
||||
Hbc.load("local-caffeine").tap do |cask|
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
let(:cask) { Hbc.load("local-caffeine") }
|
||||
let(:command) { Hbc::SystemCommand }
|
||||
let(:force) { false }
|
||||
let(:app) { Hbc::Artifact::App.new(cask, command: command, force: force) }
|
||||
|
||||
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
||||
let(:target_path) { Hbc.appdir.join("Caffeine.app") }
|
||||
|
||||
let(:install_phase) {
|
||||
lambda { app.install_phase }
|
||||
}
|
||||
|
||||
describe "install_phase" do
|
||||
it "installs the given apps using the proper target directory" do
|
||||
cask = local_caffeine
|
||||
let(:uninstall_phase) {
|
||||
lambda { app.uninstall_phase }
|
||||
}
|
||||
|
||||
before do
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
describe "install_phase" do
|
||||
it "installs the given app using the proper target directory" do
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false
|
||||
target_path.must_be :directory?
|
||||
source_path.wont_be :exist?
|
||||
end
|
||||
|
||||
it "works with an application in a subdir" do
|
||||
subdir_cask = Hbc::Cask.new("subdir") do
|
||||
url TestHelper.local_binary_url("caffeine.zip")
|
||||
homepage "http://example.com/local-caffeine"
|
||||
version "1.2.3"
|
||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||
app "subdir/Caffeine.app"
|
||||
end
|
||||
describe "when app is in a subdirectory" do
|
||||
let(:cask) {
|
||||
Hbc::Cask.new("subdir") do
|
||||
url TestHelper.local_binary_url("caffeine.zip")
|
||||
homepage "http://example.com/local-caffeine"
|
||||
version "1.2.3"
|
||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||
app "subdir/Caffeine.app"
|
||||
end
|
||||
}
|
||||
|
||||
begin
|
||||
TestHelper.install_without_artifacts(subdir_cask)
|
||||
|
||||
appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath)
|
||||
FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir)
|
||||
it "installs the given app using the proper target directory" do
|
||||
appsubdir = cask.staged_path.join("subdir").tap(&:mkpath)
|
||||
FileUtils.mv(source_path, appsubdir)
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(subdir_cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory"
|
||||
File.exist?(appsubdir.join("Caffeine.app")).must_equal false
|
||||
ensure
|
||||
if defined?(subdir_cask)
|
||||
shutup do
|
||||
Hbc::Installer.new(subdir_cask).uninstall
|
||||
end
|
||||
end
|
||||
target_path.must_be :directory?
|
||||
appsubdir.join("Caffeine.app").wont_be :exist?
|
||||
end
|
||||
end
|
||||
|
||||
it "only uses apps when they are specified" do
|
||||
cask = local_caffeine
|
||||
|
||||
staged_app_path = cask.staged_path.join("Caffeine.app")
|
||||
staged_app_copy = staged_app_path.sub("Caffeine.app", "Caffeine Deluxe.app")
|
||||
FileUtils.cp_r staged_app_path, staged_app_copy
|
||||
staged_app_copy = source_path.sub("Caffeine.app", "Caffeine Deluxe.app")
|
||||
FileUtils.cp_r source_path, staged_app_copy
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory"
|
||||
File.exist?(staged_app_path).must_equal false
|
||||
target_path.must_be :directory?
|
||||
source_path.wont_be :exist?
|
||||
|
||||
File.exist?(Hbc.appdir.join("Caffeine Deluxe.app")).must_equal false
|
||||
File.exist?(cask.staged_path.join("Caffeine Deluxe.app")).must_equal true
|
||||
Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
|
||||
cask.staged_path.join("Caffeine Deluxe.app").must_be :exist?
|
||||
end
|
||||
|
||||
describe "when the target already exists" do
|
||||
let(:target_path) {
|
||||
target_path = Hbc.appdir.join("Caffeine.app")
|
||||
before do
|
||||
target_path.mkpath
|
||||
target_path
|
||||
}
|
||||
end
|
||||
|
||||
it "avoids clobbering an existing app" do
|
||||
cask = local_caffeine
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
}, "==> It seems there is already an App at '#{target_path}'; not moving.")
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
File.identical?(source_path, target_path).must_equal false
|
||||
|
||||
contents_path = target_path.join("Contents/Info.plist")
|
||||
File.exist?(contents_path).must_equal false
|
||||
contents_path.wont_be :exist?
|
||||
end
|
||||
|
||||
describe "given the force option" do
|
||||
let(:install_phase) {
|
||||
lambda do |given_options = {}|
|
||||
options = { force: true }.merge(given_options)
|
||||
Hbc::Artifact::App.new(local_caffeine, options).install_phase
|
||||
end
|
||||
}
|
||||
|
||||
let(:chmod_cmd) {
|
||||
["/bin/chmod", "-R", "--", "u+rwx", target_path]
|
||||
}
|
||||
|
||||
let(:chmod_n_cmd) {
|
||||
["/bin/chmod", "-R", "-N", target_path]
|
||||
}
|
||||
|
||||
let(:chflags_cmd) {
|
||||
["/usr/bin/chflags", "-R", "--", "000", target_path]
|
||||
}
|
||||
let(:force) { true }
|
||||
|
||||
before do
|
||||
Hbc::Utils.stubs(current_user: "fake_user")
|
||||
@ -115,60 +97,56 @@ describe Hbc::Artifact::App do
|
||||
|
||||
describe "target is both writable and user-owned" do
|
||||
it "overwrites the existing app" do
|
||||
cask = local_caffeine
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
expected = [
|
||||
"==> It seems there is already an App at '#{target_path}'; overwriting.",
|
||||
"==> Removing App: '#{target_path}'",
|
||||
"==> Moving App 'Caffeine.app' to '#{target_path}'",
|
||||
]
|
||||
TestHelper.must_output(self, install_phase,
|
||||
expected.join("\n"))
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
|
||||
File.exist?(source_path).must_equal false
|
||||
File.ftype(target_path).must_equal "directory"
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
contents_path = target_path.join("Contents/Info.plist")
|
||||
File.exist?(contents_path).must_equal true
|
||||
contents_path.must_be :exist?
|
||||
end
|
||||
end
|
||||
|
||||
describe "target is user-owned but contains read-only files" do
|
||||
let(:command) { Hbc::FakeSystemCommand }
|
||||
|
||||
let(:chmod_cmd) {
|
||||
["/bin/chmod", "-R", "--", "u+rwx", target_path]
|
||||
}
|
||||
|
||||
let(:chmod_n_cmd) {
|
||||
["/bin/chmod", "-R", "-N", target_path]
|
||||
}
|
||||
|
||||
let(:chflags_cmd) {
|
||||
["/usr/bin/chflags", "-R", "--", "000", target_path]
|
||||
}
|
||||
|
||||
before do
|
||||
system "/usr/bin/touch", "--", "#{target_path}/foo"
|
||||
system "/bin/chmod", "--", "0555", target_path
|
||||
end
|
||||
|
||||
it "tries to make the target world-writable" do
|
||||
Hbc::FakeSystemCommand.expect_and_pass_through(chflags_cmd)
|
||||
Hbc::FakeSystemCommand.expect_and_pass_through(chmod_cmd)
|
||||
Hbc::FakeSystemCommand.expect_and_pass_through(chmod_n_cmd)
|
||||
|
||||
shutup do
|
||||
install_phase.call(command: Hbc::FakeSystemCommand)
|
||||
end
|
||||
end
|
||||
|
||||
it "overwrites the existing app" do
|
||||
cask = local_caffeine
|
||||
command.expect_and_pass_through(chflags_cmd)
|
||||
command.expect_and_pass_through(chmod_cmd)
|
||||
command.expect_and_pass_through(chmod_n_cmd)
|
||||
|
||||
expected = [
|
||||
"==> It seems there is already an App at '#{target_path}'; overwriting.",
|
||||
"==> Removing App: '#{target_path}'",
|
||||
"==> Moving App 'Caffeine.app' to '#{target_path}'",
|
||||
]
|
||||
TestHelper.must_output(self, install_phase,
|
||||
expected.join("\n"))
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
|
||||
File.exist?(source_path).must_equal false
|
||||
File.ftype(target_path).must_equal "directory"
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
contents_path = target_path.join("Contents/Info.plist")
|
||||
File.exist?(contents_path).must_equal true
|
||||
contents_path.must_be :exist?
|
||||
end
|
||||
|
||||
after do
|
||||
@ -179,15 +157,7 @@ describe Hbc::Artifact::App do
|
||||
end
|
||||
|
||||
describe "when the target is a broken symlink" do
|
||||
let(:target_path) {
|
||||
Hbc.appdir.join("Caffeine.app")
|
||||
}
|
||||
|
||||
let(:deleted_path) {
|
||||
local_caffeine.staged_path.join(
|
||||
"Deleted.app"
|
||||
)
|
||||
}
|
||||
let(:deleted_path) { cask.staged_path.join("Deleted.app") }
|
||||
|
||||
before do
|
||||
deleted_path.mkdir
|
||||
@ -196,105 +166,84 @@ describe Hbc::Artifact::App do
|
||||
end
|
||||
|
||||
it "leaves the target alone" do
|
||||
cask = local_caffeine
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
}, "==> It seems there is already an App at '#{target_path}'; not moving.")
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
|
||||
File.symlink?(target_path).must_equal true
|
||||
end
|
||||
|
||||
describe "given the force option" do
|
||||
let(:install_phase) {
|
||||
lambda do
|
||||
Hbc::Artifact::App.new(
|
||||
local_caffeine, force: true
|
||||
).install_phase
|
||||
end
|
||||
}
|
||||
let(:force) { true }
|
||||
|
||||
it "overwrites the existing app" do
|
||||
cask = local_caffeine
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
expected = [
|
||||
"==> It seems there is already an App at '#{target_path}'; overwriting.",
|
||||
"==> Removing App: '#{target_path}'",
|
||||
"==> Moving App 'Caffeine.app' to '#{target_path}'",
|
||||
]
|
||||
TestHelper.must_output(self, install_phase,
|
||||
expected.join("\n"))
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
|
||||
File.exist?(source_path).must_equal false
|
||||
File.ftype(target_path).must_equal "directory"
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
contents_path = target_path.join("Contents/Info.plist")
|
||||
File.exist?(contents_path).must_equal true
|
||||
contents_path.must_be :exist?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "gives a warning if the source doesn't exist" do
|
||||
cask = local_caffeine
|
||||
staged_app_path = cask.staged_path.join("Caffeine.app")
|
||||
staged_app_path.rmtree
|
||||
source_path.rmtree
|
||||
|
||||
installation = -> { Hbc::Artifact::App.new(cask).install_phase }
|
||||
message = "It seems the App source is not there: '#{staged_app_path}'"
|
||||
message = "It seems the App source is not there: '#{source_path}'"
|
||||
|
||||
error = installation.must_raise(Hbc::CaskError)
|
||||
error = install_phase.must_raise(Hbc::CaskError)
|
||||
error.message.must_equal message
|
||||
end
|
||||
end
|
||||
|
||||
describe "uninstall_phase" do
|
||||
before do
|
||||
shutup do
|
||||
install_phase.call
|
||||
end
|
||||
end
|
||||
|
||||
it "deletes managed apps" do
|
||||
cask = local_caffeine
|
||||
target_path.must_be :exist?
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
Hbc::Artifact::App.new(cask).uninstall_phase
|
||||
uninstall_phase.call
|
||||
end
|
||||
|
||||
app_path = Hbc.appdir.join("Caffeine.app")
|
||||
File.exist?(app_path).must_equal false
|
||||
target_path.wont_be :exist?
|
||||
end
|
||||
end
|
||||
|
||||
describe "summary" do
|
||||
let(:description) { app.summary[:english_description] }
|
||||
let(:contents) { app.summary[:contents] }
|
||||
|
||||
it "returns the correct english_description" do
|
||||
cask = local_caffeine
|
||||
|
||||
description = Hbc::Artifact::App.new(cask).summary[:english_description]
|
||||
|
||||
description.must_equal "Apps"
|
||||
end
|
||||
|
||||
describe "app is correctly installed" do
|
||||
it "returns the path to the app" do
|
||||
cask = local_caffeine
|
||||
|
||||
before do
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
end
|
||||
|
||||
contents = Hbc::Artifact::App.new(cask).summary[:contents]
|
||||
app_path = Hbc.appdir.join("Caffeine.app")
|
||||
|
||||
contents.must_equal ["#{app_path} (#{app_path.abv})"]
|
||||
it "returns the path to the app" do
|
||||
contents.must_equal ["#{target_path} (#{target_path.abv})"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "app is missing" do
|
||||
it "returns a warning and the supposed path to the app" do
|
||||
cask = local_caffeine
|
||||
|
||||
contents = Hbc::Artifact::App.new(cask).summary[:contents]
|
||||
app_path = Hbc.appdir.join("Caffeine.app")
|
||||
|
||||
contents.size.must_equal 1
|
||||
contents[0].must_match(%r{.*Missing App.*: #{app_path}})
|
||||
contents[0].must_match(%r{.*Missing App.*: #{target_path}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,44 +1,45 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::Artifact::Artifact do
|
||||
let(:cask) {
|
||||
Hbc.load("with-generic-artifact").tap do |cask|
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
let(:cask) { Hbc.load("with-generic-artifact") }
|
||||
|
||||
let(:install_phase) {
|
||||
lambda { Hbc::Artifact::Artifact.new(cask).install_phase }
|
||||
}
|
||||
|
||||
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
||||
let(:target_path) { Hbc.appdir.join("Caffeine.app") }
|
||||
|
||||
before do
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
describe "with no target" do
|
||||
let(:cask) { Hbc.load("with-generic-artifact-no-target") }
|
||||
|
||||
it "fails to install with no target" do
|
||||
install_phase.must_raise Hbc::CaskInvalidError
|
||||
end
|
||||
}
|
||||
let(:expected_path) {
|
||||
Hbc.appdir.join("Caffeine.app")
|
||||
}
|
||||
|
||||
it "fails to install with no target" do
|
||||
no_target = Hbc.load("with-generic-artifact-no-target")
|
||||
TestHelper.install_without_artifacts(no_target)
|
||||
|
||||
lambda {
|
||||
shutup do
|
||||
Hbc::Artifact::Artifact.new(no_target).install_phase
|
||||
end
|
||||
}.must_raise(Hbc::CaskInvalidError)
|
||||
end
|
||||
|
||||
it "moves the artifact to the proper directory" do
|
||||
shutup do
|
||||
Hbc::Artifact::Artifact.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false
|
||||
target_path.must_be :directory?
|
||||
source_path.wont_be :exist?
|
||||
end
|
||||
|
||||
it "avoids clobbering an existing artifact" do
|
||||
FileUtils.touch expected_path
|
||||
target_path.mkpath
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::Artifact.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine.app")
|
||||
|
||||
File.identical?(source_path, expected_path).must_equal false
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
File.identical?(source_path, target_path).must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,41 +1,46 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::Artifact::Suite do
|
||||
let(:cask) {
|
||||
Hbc.load("with-suite").tap do |cask|
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
}
|
||||
let(:expected_path) {
|
||||
Hbc.appdir.join("Caffeine")
|
||||
let(:cask) { Hbc.load("with-suite") }
|
||||
|
||||
let(:install_phase) {
|
||||
lambda { Hbc::Artifact::Suite.new(cask).install_phase }
|
||||
}
|
||||
|
||||
let(:target_path) { Hbc.appdir.join("Caffeine") }
|
||||
let(:source_path) { cask.staged_path.join("Caffeine") }
|
||||
|
||||
before do
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
it "moves the suite to the proper directory" do
|
||||
shutup do
|
||||
Hbc::Artifact::Suite.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
expected_path.must_be :directory?
|
||||
TestHelper.valid_alias?(expected_path).must_equal false
|
||||
File.exist?(source_path).must_equal false
|
||||
target_path.must_be :directory?
|
||||
TestHelper.valid_alias?(target_path).must_equal false
|
||||
source_path.wont_be :exist?
|
||||
end
|
||||
|
||||
it "creates a suite containing the expected app" do
|
||||
shutup do
|
||||
Hbc::Artifact::Suite.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
expected_path.join("Caffeine.app").must_be :exist?
|
||||
target_path.join("Caffeine.app").must_be :exist?
|
||||
end
|
||||
|
||||
it "avoids clobbering an existing suite by moving over it" do
|
||||
FileUtils.touch expected_path
|
||||
target_path.mkpath
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::Suite.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.identical?(source_path, expected_path).must_equal false
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
File.identical?(source_path, target_path).must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,96 +1,90 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::Artifact::App do
|
||||
let(:local_two_apps_caffeine) {
|
||||
Hbc.load("with-two-apps-correct").tap do |cask|
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
}
|
||||
|
||||
let(:local_two_apps_subdir) {
|
||||
Hbc.load("with-two-apps-subdir").tap do |cask|
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
}
|
||||
|
||||
describe "multiple apps" do
|
||||
it "installs both apps using the proper target directory" do
|
||||
cask = local_two_apps_caffeine
|
||||
let(:cask) { Hbc.load("with-two-apps-correct") }
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
end
|
||||
let(:install_phase) {
|
||||
lambda { Hbc::Artifact::App.new(cask).install_phase }
|
||||
}
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine Mini.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine Mini.app")).must_equal false
|
||||
let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") }
|
||||
let(:target_path_mini) { Hbc.appdir.join("Caffeine Mini.app") }
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine Pro.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine Pro.app")).must_equal false
|
||||
let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") }
|
||||
let(:target_path_pro) { Hbc.appdir.join("Caffeine Pro.app") }
|
||||
|
||||
before do
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
it "works with an application in a subdir" do
|
||||
cask = local_two_apps_subdir
|
||||
TestHelper.install_without_artifacts(cask)
|
||||
|
||||
it "installs both apps using the proper target directory" do
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine Mini.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine Mini.app")).must_equal false
|
||||
target_path_mini.must_be :directory?
|
||||
source_path_mini.wont_be :exist?
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine Pro.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine Pro.app")).must_equal false
|
||||
target_path_pro.must_be :directory?
|
||||
source_path_pro.wont_be :exist?
|
||||
end
|
||||
|
||||
describe "when apps are in a subdirectory" do
|
||||
let(:cask) { Hbc.load("with-two-apps-subdir") }
|
||||
|
||||
it "installs both apps using the proper target directory" do
|
||||
shutup do
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
target_path_mini.must_be :directory?
|
||||
source_path_mini.wont_be :exist?
|
||||
|
||||
target_path_pro.must_be :directory?
|
||||
source_path_pro.wont_be :exist?
|
||||
end
|
||||
end
|
||||
|
||||
it "only uses apps when they are specified" do
|
||||
cask = local_two_apps_caffeine
|
||||
|
||||
app_path = cask.staged_path.join("Caffeine Mini.app")
|
||||
FileUtils.cp_r app_path, app_path.sub("Caffeine Mini.app", "Caffeine Deluxe.app")
|
||||
FileUtils.cp_r source_path_mini, source_path_mini.sub("Caffeine Mini.app", "Caffeine Deluxe.app")
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
install_phase.call
|
||||
end
|
||||
|
||||
File.ftype(Hbc.appdir.join("Caffeine Mini.app")).must_equal "directory"
|
||||
File.exist?(cask.staged_path.join("Caffeine Mini.app")).must_equal false
|
||||
target_path_mini.must_be :directory?
|
||||
source_path_mini.wont_be :exist?
|
||||
|
||||
File.exist?(Hbc.appdir.join("Caffeine Deluxe.app")).must_equal false
|
||||
File.exist?(cask.staged_path.join("Caffeine Deluxe.app")).must_equal true
|
||||
Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
|
||||
cask.staged_path.join("Caffeine Deluxe.app").must_be :exist?
|
||||
end
|
||||
|
||||
describe "avoids clobbering an existing app" do
|
||||
let(:cask) { local_two_apps_caffeine }
|
||||
|
||||
it "when the first app of two already exists" do
|
||||
Hbc.appdir.join("Caffeine Mini.app").mkpath
|
||||
target_path_mini.mkpath
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
}, <<-EOS.undent.chomp)
|
||||
==> It seems there is already an App at '#{Hbc.appdir.join("Caffeine Mini.app")}'; not moving.
|
||||
==> Moving App 'Caffeine Pro.app' to '#{Hbc.appdir.join("Caffeine Pro.app")}'
|
||||
EOS
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path_mini}'; not moving.
|
||||
==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}'
|
||||
EOS
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine Mini.app")
|
||||
|
||||
File.identical?(source_path, Hbc.appdir.join("Caffeine Mini.app")).must_equal false
|
||||
source_path_mini.must_be :directory?
|
||||
target_path_mini.must_be :directory?
|
||||
File.identical?(source_path_mini, target_path_mini).must_equal false
|
||||
end
|
||||
|
||||
it "when the second app of two already exists" do
|
||||
Hbc.appdir.join("Caffeine Pro.app").mkpath
|
||||
target_path_pro.mkpath
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::Artifact::App.new(cask).install_phase
|
||||
}, <<-EOS.undent.chomp)
|
||||
==> Moving App 'Caffeine Mini.app' to '#{Hbc.appdir.join("Caffeine Mini.app")}'
|
||||
==> It seems there is already an App at '#{Hbc.appdir.join("Caffeine Pro.app")}'; not moving.
|
||||
EOS
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}'
|
||||
==> It seems there is already an App at '#{target_path_pro}'; not moving.
|
||||
EOS
|
||||
|
||||
source_path = cask.staged_path.join("Caffeine Pro.app")
|
||||
|
||||
File.identical?(source_path, Hbc.appdir.join("Caffeine Pro.app")).must_equal false
|
||||
source_path_pro.must_be :directory?
|
||||
target_path_pro.must_be :directory?
|
||||
File.identical?(source_path_pro, target_path_pro).must_equal false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -27,9 +27,9 @@ describe Hbc::CLI::Install do
|
||||
Hbc::CLI::Install.run("local-transmission")
|
||||
end
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
lambda {
|
||||
Hbc::CLI::Install.run("local-transmission", "")
|
||||
}, %r{Warning: A Cask for local-transmission is already installed.})
|
||||
}.must_output nil, %r{Warning: A Cask for local-transmission is already installed.}
|
||||
end
|
||||
|
||||
it "allows double install with --force" do
|
||||
@ -37,9 +37,9 @@ describe Hbc::CLI::Install do
|
||||
Hbc::CLI::Install.run("local-transmission")
|
||||
end
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
lambda {
|
||||
Hbc::CLI::Install.run("local-transmission", "--force")
|
||||
}, %r{==> Success! local-transmission was successfully installed!})
|
||||
}.must_output %r{==> Success! local-transmission was successfully installed!}
|
||||
end
|
||||
|
||||
it "skips dependencies with --skip-cask-deps" do
|
||||
@ -60,25 +60,19 @@ describe Hbc::CLI::Install do
|
||||
end
|
||||
|
||||
it "returns a suggestion for a misspelled Cask" do
|
||||
_, err = capture_io do
|
||||
lambda {
|
||||
begin
|
||||
Hbc::CLI::Install.run("googlechrome")
|
||||
rescue Hbc::CaskError
|
||||
return
|
||||
end
|
||||
end
|
||||
err.must_match %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome}
|
||||
rescue Hbc::CaskError; end
|
||||
}.must_output nil, %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome}
|
||||
end
|
||||
|
||||
it "returns multiple suggestions for a Cask fragment" do
|
||||
_, err = capture_io do
|
||||
lambda {
|
||||
begin
|
||||
Hbc::CLI::Install.run("google")
|
||||
rescue Hbc::CaskError
|
||||
return
|
||||
end
|
||||
end
|
||||
err.must_match %r{No available Cask for google\. Did you mean one of:\ngoogle}
|
||||
rescue Hbc::CaskError; end
|
||||
}.must_output nil, %r{No available Cask for google\. Did you mean one of:\ngoogle}
|
||||
end
|
||||
|
||||
describe "when no Cask is specified" do
|
||||
|
||||
@ -78,11 +78,11 @@ describe Hbc::CLI::List do
|
||||
lambda {
|
||||
Hbc::CLI::List.run("local-transmission", "local-caffeine")
|
||||
}.must_output <<-EOS.undent
|
||||
==> Apps
|
||||
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
|
||||
==> Apps
|
||||
Missing App: #{Hbc.appdir.join("Caffeine.app")}
|
||||
EOS
|
||||
==> Apps
|
||||
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
|
||||
==> Apps
|
||||
Missing App: #{Hbc.appdir.join("Caffeine.app")}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -36,9 +36,9 @@ describe Hbc::CLI::Uninstall do
|
||||
end
|
||||
|
||||
caffeine.wont_be :installed?
|
||||
File.exist?(Hbc.appdir.join("Transmission.app")).must_equal false
|
||||
Hbc.appdir.join("Transmission.app").wont_be :exist?
|
||||
transmission.wont_be :installed?
|
||||
File.exist?(Hbc.appdir.join("Caffeine.app")).must_equal false
|
||||
Hbc.appdir.join("Caffeine.app").wont_be :exist?
|
||||
end
|
||||
|
||||
describe "when multiple versions of a cask are installed" do
|
||||
|
||||
@ -4,6 +4,6 @@ describe "brew cask --version" do
|
||||
it "respects the --version argument" do
|
||||
lambda {
|
||||
Hbc::CLI::NullCommand.new("--version").run
|
||||
}.must_output "#{Hbc.full_version}\n"
|
||||
}.must_output Hbc.full_version
|
||||
end
|
||||
end
|
||||
|
||||
@ -31,12 +31,12 @@ describe Hbc::DSL do
|
||||
https://github.com/caskroom/homebrew-cask#reporting-bugs
|
||||
EOS
|
||||
|
||||
TestHelper.must_output(self, attempt_unknown_method, expected)
|
||||
attempt_unknown_method.must_output nil, expected
|
||||
end
|
||||
|
||||
it "will simply warn, not throw an exception" do
|
||||
begin
|
||||
capture_subprocess_io do
|
||||
shutup do
|
||||
attempt_unknown_method.call
|
||||
end
|
||||
rescue StandardError => e
|
||||
@ -70,11 +70,13 @@ describe Hbc::DSL do
|
||||
|
||||
it "may use deprecated DSL version hash syntax" do
|
||||
with_environment "HOMEBREW_DEVELOPER" => nil do
|
||||
test_cask = Hbc.load("with-dsl-version")
|
||||
test_cask.token.must_equal "with-dsl-version"
|
||||
test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg"
|
||||
test_cask.homepage.must_equal "http://example.com/"
|
||||
test_cask.version.to_s.must_equal "1.2.3"
|
||||
shutup do
|
||||
test_cask = Hbc.load("with-dsl-version")
|
||||
test_cask.token.must_equal "with-dsl-version"
|
||||
test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg"
|
||||
test_cask.homepage.must_equal "http://example.com/"
|
||||
test_cask.version.to_s.must_equal "1.2.3"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -237,17 +237,17 @@ describe Hbc::Installer do
|
||||
|
||||
it "prints caveats if they're present" do
|
||||
with_caveats = Hbc.load("with-caveats")
|
||||
TestHelper.must_output(self, lambda {
|
||||
lambda {
|
||||
Hbc::Installer.new(with_caveats).install
|
||||
}, %r{Here are some things you might want to know})
|
||||
}.must_output %r{Here are some things you might want to know}
|
||||
with_caveats.must_be :installed?
|
||||
end
|
||||
|
||||
it "prints installer :manual instructions when present" do
|
||||
with_installer_manual = Hbc.load("with-installer-manual")
|
||||
TestHelper.must_output(self, lambda {
|
||||
lambda {
|
||||
Hbc::Installer.new(with_installer_manual).install
|
||||
}, %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'})
|
||||
}.must_output %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'}
|
||||
with_installer_manual.must_be :installed?
|
||||
end
|
||||
|
||||
@ -348,7 +348,7 @@ describe Hbc::Installer do
|
||||
end
|
||||
|
||||
dest_path = Hbc.appdir.join("MyNestedApp.app")
|
||||
File.ftype(dest_path).must_equal "directory"
|
||||
dest_path.must_be :directory?
|
||||
end
|
||||
|
||||
it "generates and finds a timestamped metadata directory for an installed Cask" do
|
||||
|
||||
@ -93,20 +93,6 @@ class TestHelper
|
||||
Hbc::FakeFetcher.fake_response_for(*args)
|
||||
end
|
||||
|
||||
def self.must_output(test, lambda, expected = nil)
|
||||
out, err = test.capture_subprocess_io do
|
||||
lambda.call
|
||||
end
|
||||
|
||||
if block_given?
|
||||
yield (out + err).chomp
|
||||
elsif expected.is_a?(Regexp)
|
||||
(out + err).chomp.must_match expected
|
||||
else
|
||||
(out + err).chomp.must_equal expected.gsub(%r{^ *}, "")
|
||||
end
|
||||
end
|
||||
|
||||
def self.valid_alias?(candidate)
|
||||
return false unless candidate.symlink?
|
||||
candidate.readlink.exist?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user