diff --git a/Library/Homebrew/cask/cmd/brew-cask-tests.rb b/Library/Homebrew/cask/cmd/brew-cask-tests.rb
index bdcabd4dc8..b27bc2fe73 100755
--- a/Library/Homebrew/cask/cmd/brew-cask-tests.rb
+++ b/Library/Homebrew/cask/cmd/brew-cask-tests.rb
@@ -21,36 +21,25 @@ cask_root.cd do
system "bundle", "install"
end
- rspec = ARGV.flag?("--rspec") || !ARGV.flag?("--minitest")
- minitest = ARGV.flag?("--minitest") || !ARGV.flag?("--rspec")
-
if ARGV.flag?("--coverage")
ENV["HOMEBREW_TESTS_COVERAGE"] = "1"
upload_coverage = ENV["CODECOV_TOKEN"] || ENV["TRAVIS"]
end
- failed = false
+ run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"], %w[
+ --color
+ --require spec_helper
+ --format progress
+ --format ParallelTests::RSpec::RuntimeLogger
+ --out tmp/parallel_runtime_rspec.log
+ ]
- if rspec
- run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"], %w[
- --color
- --require spec_helper
- --format progress
- --format ParallelTests::RSpec::RuntimeLogger
- --out tmp/parallel_runtime_rspec.log
- ]
- failed ||= !$CHILD_STATUS.success?
+ unless $CHILD_STATUS.success?
+ Homebrew.failed = true
end
- if minitest
- run_tests "parallel_test", Dir["test/**/*_test.rb"]
- failed ||= !$CHILD_STATUS.success?
- end
-
- Homebrew.failed = failed
-
if upload_coverage
puts "Submitting Codecov coverage..."
- system "bundle", "exec", "test/upload_coverage.rb"
+ system "bundle", "exec", "spec/upload_coverage.rb"
end
end
diff --git a/Library/Homebrew/cask/spec/cask/accessibility_spec.rb b/Library/Homebrew/cask/spec/cask/accessibility_spec.rb
new file mode 100644
index 0000000000..8787a2c6d8
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/accessibility_spec.rb
@@ -0,0 +1,82 @@
+require "spec_helper"
+
+# TODO: this test should be named after the corresponding class, once
+# that class is abstracted from installer.rb.
+describe "Accessibility Access" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") }
+ let(:fake_system_command) { class_double(Hbc::SystemCommand) }
+ let(:installer) { Hbc::Installer.new(cask, command: fake_system_command) }
+
+ before(:each) do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new(macos_version))
+ allow(installer).to receive(:bundle_identifier).and_return("com.example.BasicCask")
+ end
+
+ context "on MacOS 10.8 and below" do
+ let(:macos_version) { "10.8" }
+
+ it "can enable accessibility access in macOS releases prior to Mavericks" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/touch",
+ args: [Hbc.pre_mavericks_accessibility_dotfile],
+ sudo: true
+ )
+
+ shutup do
+ installer.enable_accessibility_access
+ end
+ end
+
+ it "warns about disabling accessibility access on old macOS releases" do
+ expect {
+ installer.disable_accessibility_access
+ }.to output(/Warning: Accessibility access cannot be disabled automatically on this version of macOS\./).to_stderr
+ end
+ end
+
+ context "on MacOS 10.9" do
+ let(:macos_version) { "10.9" }
+
+ it "can enable accessibility access" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/sqlite3",
+ args: [Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"],
+ sudo: true
+ )
+
+ shutup do
+ installer.enable_accessibility_access
+ end
+ end
+
+ it "can disable accessibility access" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/sqlite3",
+ args: [Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"],
+ sudo: true
+ )
+
+ shutup do
+ installer.disable_accessibility_access
+ end
+ end
+ end
+
+ context "on MacOS 10.12 and above" do
+ let(:macos_version) { "10.12" }
+
+ it "warns about enabling accessibility access on new macOS releases" do
+ expect {
+ expect {
+ installer.enable_accessibility_access
+ }.to output.to_stdout
+ }.to output(/Warning: Accessibility access cannot be enabled automatically on this version of macOS\./).to_stderr
+ end
+
+ it "warns about disabling accessibility access on new macOS releases" do
+ expect {
+ installer.disable_accessibility_access
+ }.to output(/Warning: Accessibility access cannot be disabled automatically on this version of macOS\./).to_stderr
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb b/Library/Homebrew/cask/spec/cask/artifact/alt_target_spec.rb
similarity index 65%
rename from Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/alt_target_spec.rb
index 06c76f3373..9a57a9878d 100644
--- a/Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/alt_target_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::App do
describe "activate to alternate target" do
@@ -12,19 +12,19 @@ describe Hbc::Artifact::App do
let(:target_path) { Hbc.appdir.join("AnotherName.app") }
before do
- TestHelper.install_without_artifacts(cask)
+ InstallHelper.install_without_artifacts(cask)
end
it "installs the given apps using the proper target directory" do
- source_path.must_be :directory?
- target_path.wont_be :exist?
+ expect(source_path).to be_a_directory
+ expect(target_path).not_to exist
shutup do
install_phase.call
end
- target_path.must_be :directory?
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(source_path).not_to exist
end
describe "when app is in a subdirectory" do
@@ -46,8 +46,8 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path.must_be :directory?
- appsubdir.join("Caffeine.app").wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(appsubdir.join("Caffeine.app")).not_to exist
end
end
@@ -59,23 +59,21 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path.must_be :directory?
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(source_path).not_to exist
- Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
- cask.staged_path.join("Caffeine Deluxe.app").must_be :directory?
+ expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist
+ expect(cask.staged_path.join("Caffeine Deluxe.app")).to be_a_directory
end
it "avoids clobbering an existing app by moving over it" do
target_path.mkpath
- err = install_phase.must_raise(Hbc::CaskError)
+ expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.")
- err.message.must_equal("It seems there is already an App at '#{target_path}'.")
-
- source_path.must_be :directory?
- target_path.must_be :directory?
- File.identical?(source_path, target_path).must_equal false
+ expect(source_path).to be_a_directory
+ expect(target_path).to be_a_directory
+ expect(File.identical?(source_path, target_path)).to be false
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/app_test.rb b/Library/Homebrew/cask/spec/cask/artifact/app_spec.rb
similarity index 62%
rename from Library/Homebrew/cask/test/cask/artifact/app_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/app_spec.rb
index 1403a34a93..b3877f0002 100644
--- a/Library/Homebrew/cask/test/cask/artifact/app_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/app_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::App do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") }
@@ -12,8 +12,8 @@ describe Hbc::Artifact::App do
let(:install_phase) { -> { app.install_phase } }
let(:uninstall_phase) { -> { app.uninstall_phase } }
- before do
- TestHelper.install_without_artifacts(cask)
+ before(:each) do
+ InstallHelper.install_without_artifacts(cask)
end
describe "install_phase" do
@@ -22,8 +22,8 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path.must_be :directory?
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(source_path).not_to exist
end
describe "when app is in a subdirectory" do
@@ -45,8 +45,8 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path.must_be :directory?
- appsubdir.join("Caffeine.app").wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(appsubdir.join("Caffeine.app")).not_to exist
end
end
@@ -58,36 +58,34 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path.must_be :directory?
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(source_path).not_to exist
- Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
- cask.staged_path.join("Caffeine Deluxe.app").must_be :exist?
+ expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist
+ expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist
end
describe "when the target already exists" do
- before do
+ before(:each) do
target_path.mkpath
end
it "avoids clobbering an existing app" do
- err = install_phase.must_raise(Hbc::CaskError)
+ expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.")
- err.message.must_equal("It seems there is already an App at '#{target_path}'.")
-
- source_path.must_be :directory?
- target_path.must_be :directory?
- File.identical?(source_path, target_path).must_equal false
+ expect(source_path).to be_a_directory
+ expect(target_path).to be_a_directory
+ expect(File.identical?(source_path, target_path)).to be false
contents_path = target_path.join("Contents/Info.plist")
- contents_path.wont_be :exist?
+ expect(contents_path).not_to exist
end
describe "given the force option" do
let(:force) { true }
- before do
- Hbc::Utils.stubs(current_user: "fake_user")
+ before(:each) do
+ allow(Hbc::Utils).to receive(:current_user).and_return("fake_user")
end
describe "target is both writable and user-owned" do
@@ -101,40 +99,31 @@ describe Hbc::Artifact::App do
Warning: It seems there is already an App at '#{target_path}'; overwriting.
EOS
- install_phase.must_output(stdout, stderr)
+ expect {
+ expect(install_phase).to output(stdout).to_stdout
+ }.to output(stderr).to_stderr
- source_path.wont_be :exist?
- target_path.must_be :directory?
+ expect(source_path).not_to exist
+ expect(target_path).to be_a_directory
contents_path = target_path.join("Contents/Info.plist")
- contents_path.must_be :exist?
+ expect(contents_path).to 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
+ before(:each) do
system "/usr/bin/touch", "--", "#{target_path}/foo"
system "/bin/chmod", "--", "0555", target_path
end
it "overwrites the existing app" do
- command.expect_and_pass_through(chflags_cmd)
- command.expect_and_pass_through(chmod_cmd)
- command.expect_and_pass_through(chmod_n_cmd)
+ expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "--", "u+rwx", target_path], must_succeed: false)
+ .and_call_original
+ expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "-N", target_path], must_succeed: false)
+ .and_call_original
+ expect(command).to receive(:run).with("/usr/bin/chflags", args: ["-R", "--", "000", target_path], must_succeed: false)
+ .and_call_original
stdout = <<-EOS.undent
==> Removing App: '#{target_path}'
@@ -145,16 +134,18 @@ describe Hbc::Artifact::App do
Warning: It seems there is already an App at '#{target_path}'; overwriting.
EOS
- install_phase.must_output(stdout, stderr)
+ expect {
+ expect(install_phase).to output(stdout).to_stdout
+ }.to output(stderr).to_stderr
- source_path.wont_be :exist?
- target_path.must_be :directory?
+ expect(source_path).not_to exist
+ expect(target_path).to be_a_directory
contents_path = target_path.join("Contents/Info.plist")
- contents_path.must_be :exist?
+ expect(contents_path).to exist
end
- after do
+ after(:each) do
system "/bin/chmod", "--", "0755", target_path
end
end
@@ -164,18 +155,15 @@ describe Hbc::Artifact::App do
describe "when the target is a broken symlink" do
let(:deleted_path) { cask.staged_path.join("Deleted.app") }
- before do
+ before(:each) do
deleted_path.mkdir
File.symlink(deleted_path, target_path)
deleted_path.rmdir
end
it "leaves the target alone" do
- err = install_phase.must_raise(Hbc::CaskError)
-
- err.message.must_equal("It seems there is already an App at '#{target_path}'.")
-
- File.symlink?(target_path).must_equal true
+ expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.")
+ expect(target_path).to be_a_symlink
end
describe "given the force option" do
@@ -191,13 +179,15 @@ describe Hbc::Artifact::App do
Warning: It seems there is already an App at '#{target_path}'; overwriting.
EOS
- install_phase.must_output(stdout, stderr)
+ expect {
+ expect(install_phase).to output(stdout).to_stdout
+ }.to output(stderr).to_stderr
- source_path.wont_be :exist?
- target_path.must_be :directory?
+ expect(source_path).not_to exist
+ expect(target_path).to be_a_directory
contents_path = target_path.join("Contents/Info.plist")
- contents_path.must_be :exist?
+ expect(contents_path).to exist
end
end
end
@@ -207,26 +197,23 @@ describe Hbc::Artifact::App do
message = "It seems the App source is not there: '#{source_path}'"
- error = install_phase.must_raise(Hbc::CaskError)
- error.message.must_equal message
+ expect(install_phase).to raise_error(Hbc::CaskError, message)
end
end
describe "uninstall_phase" do
- before do
+ it "deletes managed apps" do
shutup do
install_phase.call
end
- end
- it "deletes managed apps" do
- target_path.must_be :exist?
+ expect(target_path).to exist
shutup do
uninstall_phase.call
end
- target_path.wont_be :exist?
+ expect(target_path).not_to exist
end
end
@@ -235,25 +222,23 @@ describe Hbc::Artifact::App do
let(:contents) { app.summary[:contents] }
it "returns the correct english_description" do
- description.must_equal "Apps"
+ expect(description).to eq("Apps")
end
describe "app is correctly installed" do
- before do
+ it "returns the path to the app" do
shutup do
install_phase.call
end
- end
- it "returns the path to the app" do
- contents.must_equal ["#{target_path} (#{target_path.abv})"]
+ expect(contents).to eq(["#{target_path} (#{target_path.abv})"])
end
end
describe "app is missing" do
it "returns a warning and the supposed path to the app" do
- contents.size.must_equal 1
- contents[0].must_match(/.*Missing App.*: #{target_path}/)
+ expect(contents.size).to eq(1)
+ expect(contents[0]).to match(/.*Missing App.*: #{target_path}/)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb b/Library/Homebrew/cask/spec/cask/artifact/generic_artifact_spec.rb
similarity index 66%
rename from Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/generic_artifact_spec.rb
index 21584b92ae..7d9128c0ea 100644
--- a/Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/generic_artifact_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::Artifact do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") }
@@ -11,14 +11,14 @@ describe Hbc::Artifact::Artifact do
let(:target_path) { Hbc.appdir.join("Caffeine.app") }
before do
- TestHelper.install_without_artifacts(cask)
+ InstallHelper.install_without_artifacts(cask)
end
describe "with no target" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") }
it "fails to install with no target" do
- install_phase.must_raise Hbc::CaskInvalidError
+ expect(install_phase).to raise_error(Hbc::CaskInvalidError)
end
end
@@ -27,21 +27,21 @@ describe Hbc::Artifact::Artifact do
install_phase.call
end
- target_path.must_be :directory?
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(source_path).not_to exist
end
it "avoids clobbering an existing artifact" do
target_path.mkpath
- assert_raises Hbc::CaskError do
+ expect {
shutup do
install_phase.call
end
- end
+ }.to raise_error(Hbc::CaskError)
- source_path.must_be :directory?
- target_path.must_be :directory?
- File.identical?(source_path, target_path).must_equal false
+ expect(source_path).to be_a_directory
+ expect(target_path).to be_a_directory
+ expect(File.identical?(source_path, target_path)).to be false
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb b/Library/Homebrew/cask/spec/cask/artifact/nested_container_spec.rb
similarity index 70%
rename from Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/nested_container_spec.rb
index 4d7ceaaa04..31a1cb5eb6 100644
--- a/Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/nested_container_spec.rb
@@ -1,17 +1,17 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::NestedContainer do
describe "install" do
it "extracts the specified paths as containers" do
cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb").tap do |c|
- TestHelper.install_without_artifacts(c)
+ InstallHelper.install_without_artifacts(c)
end
shutup do
Hbc::Artifact::NestedContainer.new(cask).install_phase
end
- cask.staged_path.join("MyNestedApp.app").must_be :directory?
+ expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory
end
end
end
diff --git a/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb
new file mode 100644
index 0000000000..d4d69ea663
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb
@@ -0,0 +1,71 @@
+require "spec_helper"
+
+describe Hbc::Artifact::Pkg do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") }
+ let(:fake_system_command) { class_double(Hbc::SystemCommand) }
+
+ before(:each) do
+ shutup do
+ InstallHelper.install_without_artifacts(cask)
+ end
+ end
+
+ describe "install_phase" do
+ it "runs the system installer on the specified pkgs" do
+ pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command)
+
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/installer",
+ args: ["-pkg", cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"],
+ sudo: true,
+ print_stdout: true
+ )
+
+ shutup do
+ pkg.install_phase
+ end
+ end
+ end
+
+ describe "choices" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") }
+
+ it "passes the choice changes xml to the system installer" do
+ pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command)
+
+ file = double(path: Pathname.new("/tmp/choices.xml"))
+
+ expect(file).to receive(:write).with(<<-EOS.undent)
+
+
+
+
+ \t
+ \t\tattributeSetting
+ \t\t1
+ \t\tchoiceAttribute
+ \t\tselected
+ \t\tchoiceIdentifier
+ \t\tchoice1
+ \t
+
+
+ EOS
+
+ expect(file).to receive(:close)
+ expect(file).to receive(:unlink)
+ expect(Tempfile).to receive(:open).and_yield(file)
+
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/installer",
+ args: ["-pkg", cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/", "-applyChoiceChangesXML", cask.staged_path.join("/tmp/choices.xml")],
+ sudo: true,
+ print_stdout: true
+ )
+
+ shutup do
+ pkg.install_phase
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb b/Library/Homebrew/cask/spec/cask/artifact/postflight_block_spec.rb
similarity index 64%
rename from Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/postflight_block_spec.rb
index 47dcdd905b..6f58afb2ad 100644
--- a/Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/postflight_block_spec.rb
@@ -1,9 +1,9 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::PostflightBlock do
describe "install_phase" do
it "calls the specified block after installing, passing a Cask mini-dsl" do
- called = false
+ called = false
yielded_arg = nil
cask = Hbc::Cask.new("with-postflight") do
@@ -13,16 +13,16 @@ describe Hbc::Artifact::PostflightBlock do
end
end
- Hbc::Artifact::PostflightBlock.new(cask).install_phase
+ described_class.new(cask).install_phase
- called.must_equal true
- yielded_arg.must_be_kind_of Hbc::DSL::Postflight
+ expect(called).to be true
+ expect(yielded_arg).to be_kind_of(Hbc::DSL::Postflight)
end
end
describe "uninstall_phase" do
it "calls the specified block after uninstalling, passing a Cask mini-dsl" do
- called = false
+ called = false
yielded_arg = nil
cask = Hbc::Cask.new("with-uninstall-postflight") do
@@ -32,10 +32,10 @@ describe Hbc::Artifact::PostflightBlock do
end
end
- Hbc::Artifact::PostflightBlock.new(cask).uninstall_phase
+ described_class.new(cask).uninstall_phase
- called.must_equal true
- yielded_arg.must_be_kind_of Hbc::DSL::UninstallPostflight
+ expect(called).to be true
+ expect(yielded_arg).to be_kind_of(Hbc::DSL::UninstallPostflight)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb b/Library/Homebrew/cask/spec/cask/artifact/preflight_block_spec.rb
similarity index 64%
rename from Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/preflight_block_spec.rb
index 440b1db3a4..ac5313bcae 100644
--- a/Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/preflight_block_spec.rb
@@ -1,9 +1,9 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::PreflightBlock do
describe "install_phase" do
it "calls the specified block before installing, passing a Cask mini-dsl" do
- called = false
+ called = false
yielded_arg = nil
cask = Hbc::Cask.new("with-preflight") do
@@ -13,16 +13,16 @@ describe Hbc::Artifact::PreflightBlock do
end
end
- Hbc::Artifact::PreflightBlock.new(cask).install_phase
+ described_class.new(cask).install_phase
- called.must_equal true
- yielded_arg.must_be_kind_of Hbc::DSL::Preflight
+ expect(called).to be true
+ expect(yielded_arg).to be_kind_of Hbc::DSL::Preflight
end
end
describe "uninstall_phase" do
it "calls the specified block before uninstalling, passing a Cask mini-dsl" do
- called = false
+ called = false
yielded_arg = nil
cask = Hbc::Cask.new("with-uninstall-preflight") do
@@ -32,10 +32,10 @@ describe Hbc::Artifact::PreflightBlock do
end
end
- Hbc::Artifact::PreflightBlock.new(cask).uninstall_phase
+ described_class.new(cask).uninstall_phase
- called.must_equal true
- yielded_arg.must_be_kind_of Hbc::DSL::UninstallPreflight
+ expect(called).to be true
+ expect(yielded_arg).to be_kind_of Hbc::DSL::UninstallPreflight
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/suite_test.rb b/Library/Homebrew/cask/spec/cask/artifact/suite_spec.rb
similarity index 56%
rename from Library/Homebrew/cask/test/cask/artifact/suite_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/suite_spec.rb
index 6259baa4be..79ca0546c0 100644
--- a/Library/Homebrew/cask/test/cask/artifact/suite_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/suite_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::Suite do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") }
@@ -8,20 +8,21 @@ describe Hbc::Artifact::Suite do
let(:target_path) { Hbc.appdir.join("Caffeine") }
let(:source_path) { cask.staged_path.join("Caffeine") }
- before do
- TestHelper.install_without_artifacts(cask)
+ before(:each) do
+ InstallHelper.install_without_artifacts(cask)
end
it "moves the suite to the proper directory" do
- skip("flaky test")
+ skip("flaky test") # FIXME
shutup do
install_phase.call
end
- target_path.must_be :directory?
- TestHelper.valid_symlink?(target_path).must_equal false
- source_path.wont_be :exist?
+ expect(target_path).to be_a_directory
+ expect(target_path).to be_a_symlink
+ expect(target_path.readlink).to exist
+ expect(source_path).not_to exist
end
it "creates a suite containing the expected app" do
@@ -29,20 +30,20 @@ describe Hbc::Artifact::Suite do
install_phase.call
end
- target_path.join("Caffeine.app").must_be :exist?
+ expect(target_path.join("Caffeine.app")).to exist
end
it "avoids clobbering an existing suite by moving over it" do
target_path.mkpath
- assert_raises Hbc::CaskError do
+ expect {
shutup do
install_phase.call
end
- end
+ }.to raise_error(Hbc::CaskError)
- source_path.must_be :directory?
- target_path.must_be :directory?
- File.identical?(source_path, target_path).must_equal false
+ expect(source_path).to be_a_directory
+ expect(target_path).to be_a_directory
+ expect(File.identical?(source_path, target_path)).to be false
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb b/Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb
similarity index 53%
rename from Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb
index c6ad9db47e..7fa44dbce8 100644
--- a/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::App do
describe "multiple apps" do
@@ -14,8 +14,8 @@ describe Hbc::Artifact::App do
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)
+ before(:each) do
+ InstallHelper.install_without_artifacts(cask)
end
it "installs both apps using the proper target directory" do
@@ -23,11 +23,11 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path_mini.must_be :directory?
- source_path_mini.wont_be :exist?
+ expect(target_path_mini).to be_a_directory
+ expect(source_path_mini).not_to exist
- target_path_pro.must_be :directory?
- source_path_pro.wont_be :exist?
+ expect(target_path_pro).to be_a_directory
+ expect(source_path_pro).not_to exist
end
describe "when apps are in a subdirectory" do
@@ -38,11 +38,11 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path_mini.must_be :directory?
- source_path_mini.wont_be :exist?
+ expect(target_path_mini).to be_a_directory
+ expect(source_path_mini).not_to exist
- target_path_pro.must_be :directory?
- source_path_pro.wont_be :exist?
+ expect(target_path_pro).to be_a_directory
+ expect(source_path_pro).not_to exist
end
end
@@ -53,44 +53,40 @@ describe Hbc::Artifact::App do
install_phase.call
end
- target_path_mini.must_be :directory?
- source_path_mini.wont_be :exist?
+ expect(target_path_mini).to be_a_directory
+ expect(source_path_mini).not_to exist
- Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist?
- cask.staged_path.join("Caffeine Deluxe.app").must_be :exist?
+ expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist
+ expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist
end
describe "avoids clobbering an existing app" do
it "when the first app of two already exists" do
target_path_mini.mkpath
- err = assert_raises Hbc::CaskError do
- install_phase.must_output <<-EOS.undent
+ expect {
+ expect(install_phase).to output(<<-EOS.undent).to_stdout
==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}'
EOS
- end
+ }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path_mini}'.")
- err.message.must_equal("It seems there is already an App at '#{target_path_mini}'.")
-
- source_path_mini.must_be :directory?
- target_path_mini.must_be :directory?
- File.identical?(source_path_mini, target_path_mini).must_equal false
+ expect(source_path_mini).to be_a_directory
+ expect(target_path_mini).to be_a_directory
+ expect(File.identical?(source_path_mini, target_path_mini)).to be false
end
it "when the second app of two already exists" do
target_path_pro.mkpath
- err = assert_raises Hbc::CaskError do
- install_phase.must_output <<-EOS.undent
+ expect {
+ expect(install_phase).to output(<<-EOS.undent).to_stdout
==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}'
EOS
- end
+ }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path_pro}'.")
- err.message.must_equal("It seems there is already an App at '#{target_path_pro}'.")
-
- source_path_pro.must_be :directory?
- target_path_pro.must_be :directory?
- File.identical?(source_path_pro, target_path_pro).must_equal false
+ expect(source_path_pro).to be_a_directory
+ expect(target_path_pro).to be_a_directory
+ expect(File.identical?(source_path_pro, target_path_pro)).to be false
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb b/Library/Homebrew/cask/spec/cask/artifact/two_apps_incorrect_spec.rb
similarity index 94%
rename from Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/two_apps_incorrect_spec.rb
index a79fc63783..0aa38d9106 100644
--- a/Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/two_apps_incorrect_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::App do
# FIXME: Doesn't actually raise because the `app` stanza is not evaluated on load.
diff --git a/Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb b/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
similarity index 93%
rename from Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
index 464cad3454..008e2ad2aa 100644
--- a/Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Artifact::Uninstall do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") }
@@ -7,9 +7,9 @@ describe Hbc::Artifact::Uninstall do
Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand)
}
- before do
+ before(:each) do
shutup do
- TestHelper.install_without_artifacts(cask)
+ InstallHelper.install_without_artifacts(cask)
end
end
@@ -20,7 +20,7 @@ describe Hbc::Artifact::Uninstall do
end
}
- describe "when using launchctl" do
+ context "when using launchctl" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-launchctl.rb") }
let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] }
let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] }
@@ -40,7 +40,7 @@ describe Hbc::Artifact::Uninstall do
EOS
}
- describe "when launchctl job is owned by user" do
+ context "when launchctl job is owned by user" do
it "can uninstall" do
Hbc::FakeSystemCommand.stubs_command(
launchctl_list_cmd,
@@ -58,7 +58,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when launchctl job is owned by system" do
+ context "when launchctl job is owned by system" do
it "can uninstall" do
Hbc::FakeSystemCommand.stubs_command(
launchctl_list_cmd,
@@ -77,7 +77,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using pkgutil" do
+ context "when using pkgutil" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-pkgutil.rb") }
let(:main_pkg_id) { "my.fancy.package.main" }
let(:agent_pkg_id) { "my.fancy.package.agent" }
@@ -163,7 +163,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using kext" do
+ context "when using kext" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-kext.rb") }
let(:kext_id) { "my.fancy.package.kernelextension" }
@@ -188,7 +188,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using quit" do
+ context "when using quit" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-quit.rb") }
let(:bundle_id) { "my.fancy.package.app" }
let(:quit_application_script) {
@@ -208,7 +208,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using signal" do
+ context "when using signal" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-signal.rb") }
let(:bundle_id) { "my.fancy.package.app" }
let(:signals) { %w[TERM KILL] }
@@ -220,14 +220,14 @@ describe Hbc::Artifact::Uninstall do
)
signals.each do |signal|
- Process.expects(:kill).with(signal, *unix_pids)
+ expect(Process).to receive(:kill).with(signal, *unix_pids)
end
subject
end
end
- describe "when using delete" do
+ context "when using delete" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-delete.rb") }
it "can uninstall" do
@@ -241,7 +241,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using trash" do
+ context "when using trash" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-trash.rb") }
it "can uninstall" do
@@ -255,7 +255,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using rmdir" do
+ context "when using rmdir" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-rmdir.rb") }
let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") }
@@ -272,7 +272,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using script" do
+ context "when using script" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script.rb") }
let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") }
@@ -287,7 +287,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using early_script" do
+ context "when using early_script" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-early-script.rb") }
let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") }
@@ -302,7 +302,7 @@ describe Hbc::Artifact::Uninstall do
end
end
- describe "when using login_item" do
+ context "when using login_item" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-login-item.rb") }
it "can uninstall" do
diff --git a/Library/Homebrew/cask/test/cask/artifact/zap_test.rb b/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
similarity index 93%
rename from Library/Homebrew/cask/test/cask/artifact/zap_test.rb
rename to Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
index 37a65f863e..bd14cd6dea 100644
--- a/Library/Homebrew/cask/test/cask/artifact/zap_test.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
# TODO: test that zap removes an alternate version of the same Cask
describe Hbc::Artifact::Zap do
@@ -8,9 +8,9 @@ describe Hbc::Artifact::Zap do
Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand)
}
- before do
+ before(:each) do
shutup do
- TestHelper.install_without_artifacts(cask)
+ InstallHelper.install_without_artifacts(cask)
end
end
@@ -21,7 +21,7 @@ describe Hbc::Artifact::Zap do
end
}
- describe "when using launchctl" do
+ context "when using launchctl" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-launchctl.rb") }
let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] }
let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] }
@@ -41,7 +41,7 @@ describe Hbc::Artifact::Zap do
EOS
}
- describe "when launchctl job is owned by user" do
+ context "when launchctl job is owned by user" do
it "can zap" do
Hbc::FakeSystemCommand.stubs_command(
launchctl_list_cmd,
@@ -78,7 +78,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using pkgutil" do
+ context "when using pkgutil" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-pkgutil.rb") }
let(:main_pkg_id) { "my.fancy.package.main" }
let(:agent_pkg_id) { "my.fancy.package.agent" }
@@ -164,7 +164,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using kext" do
+ context "when using kext" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-kext.rb") }
let(:kext_id) { "my.fancy.package.kernelextension" }
@@ -189,7 +189,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using quit" do
+ context "when using quit" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-quit.rb") }
let(:bundle_id) { "my.fancy.package.app" }
let(:quit_application_script) {
@@ -209,7 +209,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using signal" do
+ context "when using signal" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-signal.rb") }
let(:bundle_id) { "my.fancy.package.app" }
let(:signals) { %w[TERM KILL] }
@@ -221,14 +221,14 @@ describe Hbc::Artifact::Zap do
)
signals.each do |signal|
- Process.expects(:kill).with(signal, *unix_pids)
+ expect(Process).to receive(:kill).with(signal, *unix_pids)
end
subject
end
end
- describe "when using delete" do
+ context "when using delete" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-delete.rb") }
it "can zap" do
@@ -242,7 +242,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using trash" do
+ context "when using trash" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-trash.rb") }
it "can zap" do
@@ -256,7 +256,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using rmdir" do
+ context "when using rmdir" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-rmdir.rb") }
let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") }
@@ -273,7 +273,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using script" do
+ context "when using script" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-script.rb") }
let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") }
@@ -288,7 +288,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using early_script" do
+ context "when using early_script" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-early-script.rb") }
let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") }
@@ -303,7 +303,7 @@ describe Hbc::Artifact::Zap do
end
end
- describe "when using login_item" do
+ context "when using login_item" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-login-item.rb") }
it "can zap" do
diff --git a/Library/Homebrew/cask/spec/cask/cask_spec.rb b/Library/Homebrew/cask/spec/cask/cask_spec.rb
index d470c6ec37..32f3d82580 100644
--- a/Library/Homebrew/cask/spec/cask/cask_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/cask_spec.rb
@@ -20,4 +20,73 @@ describe Hbc::Cask do
end
end
end
+
+ describe "load" do
+ let(:hbc_relative_tap_path) { "../../Taps/caskroom/homebrew-cask" }
+
+ it "returns an instance of the Cask for the given token" do
+ c = Hbc.load("adium")
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("adium")
+ end
+
+ it "returns an instance of the Cask from a specific file location" do
+ location = File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb")
+ c = Hbc.load(location)
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("dia")
+ end
+
+ it "returns an instance of the Cask from a url" do
+ url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb")
+ c = shutup do
+ Hbc.load(url)
+ end
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("dia")
+ end
+
+ it "raises an error when failing to download a Cask from a url" do
+ expect {
+ url = "file://" + File.expand_path(hbc_relative_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(hbc_relative_tap_path + "/Casks/bbedit.rb")
+ expect(c).to be_kind_of(Hbc::Cask)
+ expect(c.token).to eq("bbedit")
+ 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 = "adium"
+ 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
diff --git a/Library/Homebrew/cask/spec/cask/cli/audit_spec.rb b/Library/Homebrew/cask/spec/cask/cli/audit_spec.rb
new file mode 100644
index 0000000000..b520a88df8
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/cli/audit_spec.rb
@@ -0,0 +1,61 @@
+require "spec_helper"
+
+describe Hbc::CLI::Audit do
+ let(:auditor) { double }
+ let(:cask) { double }
+
+ describe "selection of Casks to audit" do
+ it "audits all Casks if no tokens are given" do
+ allow(Hbc).to receive(:all).and_return([cask, cask])
+
+ expect(auditor).to receive(:audit).twice
+
+ run_audit([], auditor)
+ end
+
+ it "audits specified Casks if tokens are given" do
+ cask_token = "nice-app"
+ expect(Hbc).to receive(:load).with(cask_token).and_return(cask)
+
+ expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
+
+ run_audit([cask_token], auditor)
+ end
+ end
+
+ describe "rules for downloading a Cask" do
+ it "does not download the Cask per default" do
+ allow(Hbc).to receive(:load).and_return(cask)
+ expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
+
+ run_audit(["casktoken"], auditor)
+ end
+
+ it "download a Cask if --download flag is set" do
+ allow(Hbc).to receive(:load).and_return(cask)
+ expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false)
+
+ run_audit(["casktoken", "--download"], auditor)
+ end
+ end
+
+ describe "rules for checking token conflicts" do
+ it "does not check for token conflicts per default" do
+ allow(Hbc).to receive(:load).and_return(cask)
+ expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
+
+ run_audit(["casktoken"], auditor)
+ end
+
+ it "checks for token conflicts if --token-conflicts flag is set" do
+ allow(Hbc).to receive(:load).and_return(cask)
+ expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true)
+
+ run_audit(["casktoken", "--token-conflicts"], auditor)
+ end
+ end
+
+ def run_audit(args, auditor)
+ Hbc::CLI::Audit.new(args, auditor).run
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/cli/cat_test.rb b/Library/Homebrew/cask/spec/cask/cli/cat_spec.rb
similarity index 70%
rename from Library/Homebrew/cask/test/cask/cli/cat_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/cat_spec.rb
index 2eca9cfe9d..7517c1b5c5 100644
--- a/Library/Homebrew/cask/test/cask/cli/cat_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/cat_spec.rb
@@ -1,9 +1,9 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Cat do
describe "given a basic Cask" do
- before do
- @expected_output = <<-EOS.undent
+ let(:expected_output) {
+ <<-EOS.undent
cask 'basic-cask' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
@@ -14,46 +14,46 @@ describe Hbc::CLI::Cat do
app 'TestCask.app'
end
EOS
- end
+ }
it "displays the Cask file content about the specified Cask" do
- lambda {
+ expect {
Hbc::CLI::Cat.run("basic-cask")
- }.must_output(@expected_output)
+ }.to output(expected_output).to_stdout
end
it "throws away additional Cask arguments and uses the first" do
- lambda {
+ expect {
Hbc::CLI::Cat.run("basic-cask", "local-caffeine")
- }.must_output(@expected_output)
+ }.to output(expected_output).to_stdout
end
it "throws away stray options" do
- lambda {
+ expect {
Hbc::CLI::Cat.run("--notavalidoption", "basic-cask")
- }.must_output(@expected_output)
+ }.to output(expected_output).to_stdout
end
end
it "raises an exception when the Cask does not exist" do
- lambda {
+ expect {
Hbc::CLI::Cat.run("notacask")
- }.must_raise Hbc::CaskUnavailableError
+ }.to raise_error(Hbc::CaskUnavailableError)
end
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Cat.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Cat.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/create_test.rb b/Library/Homebrew/cask/spec/cask/cli/create_spec.rb
similarity index 78%
rename from Library/Homebrew/cask/test/cask/cli/create_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/create_spec.rb
index f09c91e8ec..e3d484d879 100644
--- a/Library/Homebrew/cask/test/cask/cli/create_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/create_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
# monkeypatch for testing
module Hbc
@@ -20,11 +20,11 @@ module Hbc
end
describe Hbc::CLI::Create do
- before do
+ before(:each) do
Hbc::CLI::Create.reset!
end
- after do
+ after(:each) do
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
path = Hbc.path(cask)
path.delete if path.exist?
@@ -33,7 +33,7 @@ describe Hbc::CLI::Create do
it "opens the editor for the specified Cask" do
Hbc::CLI::Create.run("new-cask")
- Hbc::CLI::Create.editor_commands.must_equal [
+ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("new-cask")],
]
end
@@ -41,7 +41,7 @@ describe Hbc::CLI::Create do
it "drops a template down for the specified Cask" do
Hbc::CLI::Create.run("new-cask")
template = File.read(Hbc.path("new-cask"))
- template.must_equal <<-EOS.undent
+ expect(template).to eq <<-EOS.undent
cask 'new-cask' do
version ''
sha256 ''
@@ -57,44 +57,44 @@ describe Hbc::CLI::Create do
it "throws away additional Cask arguments and uses the first" do
Hbc::CLI::Create.run("additional-cask", "another-cask")
- Hbc::CLI::Create.editor_commands.must_equal [
+ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("additional-cask")],
]
end
it "throws away stray options" do
Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask")
- Hbc::CLI::Create.editor_commands.must_equal [
+ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("yet-another-cask")],
]
end
it "raises an exception when the Cask already exists" do
- lambda {
+ expect {
Hbc::CLI::Create.run("basic-cask")
- }.must_raise Hbc::CaskAlreadyCreatedError
+ }.to raise_error(Hbc::CaskAlreadyCreatedError)
end
it "allows creating Casks that are substrings of existing Casks" do
Hbc::CLI::Create.run("local-caff")
- Hbc::CLI::Create.editor_commands.must_equal [
+ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("local-caff")],
]
end
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Create.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Create.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/edit_test.rb b/Library/Homebrew/cask/spec/cask/cli/edit_spec.rb
similarity index 63%
rename from Library/Homebrew/cask/test/cask/cli/edit_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/edit_spec.rb
index 6eb2289c02..5ddf27a48a 100644
--- a/Library/Homebrew/cask/test/cask/cli/edit_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/edit_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
# monkeypatch for testing
module Hbc
@@ -20,43 +20,43 @@ module Hbc
end
describe Hbc::CLI::Edit do
- before do
+ before(:each) do
Hbc::CLI::Edit.reset!
end
it "opens the editor for the specified Cask" do
- Hbc::CLI::Edit.run("alfred")
- Hbc::CLI::Edit.editor_commands.must_equal [
- [Hbc.path("alfred")],
+ Hbc::CLI::Edit.run("local-caffeine")
+ expect(Hbc::CLI::Edit.editor_commands).to eq [
+ [Hbc.path("local-caffeine")],
]
end
it "throws away additional arguments and uses the first" do
- Hbc::CLI::Edit.run("adium", "alfred")
- Hbc::CLI::Edit.editor_commands.must_equal [
- [Hbc.path("adium")],
+ Hbc::CLI::Edit.run("local-caffeine", "local-transmission")
+ expect(Hbc::CLI::Edit.editor_commands).to eq [
+ [Hbc.path("local-caffeine")],
]
end
it "raises an exception when the Cask doesnt exist" do
- lambda {
+ expect {
Hbc::CLI::Edit.run("notacask")
- }.must_raise Hbc::CaskUnavailableError
+ }.to raise_error(Hbc::CaskUnavailableError)
end
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Edit.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Edit.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/fetch_test.rb b/Library/Homebrew/cask/spec/cask/cli/fetch_spec.rb
similarity index 77%
rename from Library/Homebrew/cask/test/cask/cli/fetch_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/fetch_spec.rb
index 8dd7e0ebfb..bb81334532 100644
--- a/Library/Homebrew/cask/test/cask/cli/fetch_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/fetch_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Fetch do
let(:local_transmission) {
@@ -13,8 +13,8 @@ describe Hbc::CLI::Fetch do
shutup do
Hbc::CLI::Fetch.run("local-transmission", "local-caffeine")
end
- Hbc::CurlDownloadStrategy.new(local_transmission).cached_location.must_be :exist?
- Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location.must_be :exist?
+ expect(Hbc::CurlDownloadStrategy.new(local_transmission).cached_location).to exist
+ expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist
end
it "prevents double fetch (without nuking existing installation)" do
@@ -30,7 +30,7 @@ describe Hbc::CLI::Fetch do
end
new_ctime = File.stat(download_stategy.cached_location).ctime
- old_ctime.to_i.must_equal new_ctime.to_i
+ expect(old_ctime.to_i).to eq(new_ctime.to_i)
end
it "allows double fetch with --force" do
@@ -48,31 +48,30 @@ describe Hbc::CLI::Fetch do
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
new_ctime = File.stat(download_stategy.cached_location).ctime
- # new_ctime.to_i.must_be :>, old_ctime.to_i
- new_ctime.to_i.must_be :>, old_ctime.to_i
+ expect(new_ctime.to_i).to be > old_ctime.to_i
end
it "properly handles Casks that are not present" do
- lambda {
+ expect {
shutup do
Hbc::CLI::Fetch.run("notacask")
end
- }.must_raise Hbc::CaskUnavailableError
+ }.to raise_error(Hbc::CaskUnavailableError)
end
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Fetch.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Fetch.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/home_test.rb b/Library/Homebrew/cask/spec/cask/cli/home_spec.rb
similarity index 56%
rename from Library/Homebrew/cask/test/cask/cli/home_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/home_spec.rb
index 67bcb024a5..a2b49b4333 100644
--- a/Library/Homebrew/cask/test/cask/cli/home_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/home_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
# monkeypatch for testing
module Hbc
@@ -25,23 +25,23 @@ describe Hbc::CLI::Home do
end
it "opens the homepage for the specified Cask" do
- Hbc::CLI::Home.run("alfred")
- Hbc::CLI::Home.system_commands.must_equal [
- ["/usr/bin/open", "--", "https://www.alfredapp.com/"],
+ Hbc::CLI::Home.run("local-caffeine")
+ expect(Hbc::CLI::Home.system_commands).to eq [
+ ["/usr/bin/open", "--", "http://example.com/local-caffeine"],
]
end
it "works for multiple Casks" do
- Hbc::CLI::Home.run("alfred", "adium")
- Hbc::CLI::Home.system_commands.must_equal [
- ["/usr/bin/open", "--", "https://www.alfredapp.com/"],
- ["/usr/bin/open", "--", "https://www.adium.im/"],
+ Hbc::CLI::Home.run("local-caffeine", "local-transmission")
+ expect(Hbc::CLI::Home.system_commands).to eq [
+ ["/usr/bin/open", "--", "http://example.com/local-caffeine"],
+ ["/usr/bin/open", "--", "http://example.com/local-transmission"],
]
end
it "opens the project page when no Cask is specified" do
Hbc::CLI::Home.run
- Hbc::CLI::Home.system_commands.must_equal [
+ expect(Hbc::CLI::Home.system_commands).to eq [
["/usr/bin/open", "--", "http://caskroom.io/"],
]
end
diff --git a/Library/Homebrew/cask/test/cask/cli/info_test.rb b/Library/Homebrew/cask/spec/cask/cli/info_spec.rb
similarity index 74%
rename from Library/Homebrew/cask/test/cask/cli/info_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/info_spec.rb
index 767a594e8b..6977f81c3b 100644
--- a/Library/Homebrew/cask/test/cask/cli/info_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/info_spec.rb
@@ -1,14 +1,14 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Info do
it "displays some nice info about the specified Cask" do
- lambda {
+ expect {
Hbc::CLI::Info.run("local-caffeine")
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
local-caffeine: 1.2.3
http://example.com/local-caffeine
Not installed
- From: https://github.com/caskroom/homebrew-test/blob/master/Casks/local-caffeine.rb
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/local-caffeine.rb
==> Name
None
==> Artifacts
@@ -17,12 +17,12 @@ describe Hbc::CLI::Info do
end
describe "given multiple Casks" do
- before do
- @expected_output = <<-EOS.undent
+ let(:expected_output) {
+ <<-EOS.undent
local-caffeine: 1.2.3
http://example.com/local-caffeine
Not installed
- From: https://github.com/caskroom/homebrew-test/blob/master/Casks/local-caffeine.rb
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/local-caffeine.rb
==> Name
None
==> Artifacts
@@ -30,35 +30,35 @@ describe Hbc::CLI::Info do
local-transmission: 2.61
http://example.com/local-transmission
Not installed
- From: https://github.com/caskroom/homebrew-test/blob/master/Casks/local-transmission.rb
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/local-transmission.rb
==> Name
None
==> Artifacts
Transmission.app (app)
EOS
- end
+ }
it "displays the info" do
- lambda {
+ expect {
Hbc::CLI::Info.run("local-caffeine", "local-transmission")
- }.must_output(@expected_output)
+ }.to output(expected_output).to_stdout
end
it "throws away stray options" do
- lambda {
+ expect {
Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission")
- }.must_output(@expected_output)
+ }.to output(expected_output).to_stdout
end
end
it "should print caveats if the Cask provided one" do
- lambda {
+ expect {
Hbc::CLI::Info.run("with-caveats")
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
with-caveats: 1.2.3
http://example.com/local-caffeine
Not installed
- From: https://github.com/caskroom/homebrew-test/blob/master/Casks/with-caveats.rb
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-caveats.rb
==> Name
None
==> Artifacts
@@ -78,13 +78,13 @@ describe Hbc::CLI::Info do
end
it 'should not print "Caveats" section divider if the caveats block has no output' do
- lambda {
+ expect {
Hbc::CLI::Info.run("with-conditional-caveats")
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
with-conditional-caveats: 1.2.3
http://example.com/local-caffeine
Not installed
- From: https://github.com/caskroom/homebrew-test/blob/master/Casks/with-conditional-caveats.rb
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-caveats.rb
==> Name
None
==> Artifacts
@@ -94,17 +94,17 @@ describe Hbc::CLI::Info do
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Info.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Info.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/install_test.rb b/Library/Homebrew/cask/spec/cask/cli/install_spec.rb
similarity index 55%
rename from Library/Homebrew/cask/test/cask/cli/install_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/install_spec.rb
index d47d55a50c..07aa78aa3f 100644
--- a/Library/Homebrew/cask/test/cask/cli/install_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/install_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Install do
it "allows staging and activation of multiple Casks at once" do
@@ -6,10 +6,10 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission", "local-caffeine")
end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed?
- Hbc.appdir.join("Transmission.app").must_be :directory?
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").must_be :installed?
- Hbc.appdir.join("Caffeine.app").must_be :directory?
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ expect(Hbc.appdir.join("Transmission.app")).to be_a_directory
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).to be_installed
+ expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory
end
it "skips double install (without nuking existing installation)" do
@@ -19,7 +19,7 @@ describe Hbc::CLI::Install do
shutup do
Hbc::CLI::Install.run("local-transmission")
end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed?
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
end
it "prints a warning message on double install" do
@@ -27,9 +27,9 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission")
end
- lambda {
+ expect {
Hbc::CLI::Install.run("local-transmission", "")
- }.must_output nil, /Warning: A Cask for local-transmission is already installed./
+ }.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr
end
it "allows double install with --force" do
@@ -37,54 +37,56 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission")
end
- lambda {
- Hbc::CLI::Install.run("local-transmission", "--force")
- }.must_output(/local-transmission was successfully installed!/)
+ expect {
+ expect {
+ Hbc::CLI::Install.run("local-transmission", "--force")
+ }.to output(/It seems there is already an App at.*overwriting\./).to_stderr
+ }.to output(/local-transmission was successfully installed!/).to_stdout
end
it "skips dependencies with --skip-cask-deps" do
shutup do
Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps")
end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb").must_be :installed?
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").wont_be :installed?
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").wont_be :installed?
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed
end
it "properly handles Casks that are not present" do
- lambda {
+ expect {
shutup do
Hbc::CLI::Install.run("notacask")
end
- }.must_raise Hbc::CaskError
+ }.to raise_error(Hbc::CaskError)
end
it "returns a suggestion for a misspelled Cask" do
- lambda {
+ expect {
begin
Hbc::CLI::Install.run("googlechrome")
rescue Hbc::CaskError
nil
end
- }.must_output(nil, /No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/)
+ }.to output(/No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/).to_stderr
end
it "returns multiple suggestions for a Cask fragment" do
- lambda {
+ expect {
begin
Hbc::CLI::Install.run("google")
rescue Hbc::CaskError
nil
end
- }.must_output(nil, /No available Cask for google\. Did you mean one of:\ngoogle/)
+ }.to output(/No available Cask for google\. Did you mean one of:\ngoogle/).to_stderr
end
describe "when no Cask is specified" do
with_options = lambda do |options|
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Install.run(*options)
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/list_test.rb b/Library/Homebrew/cask/spec/cask/cli/list_spec.rb
similarity index 76%
rename from Library/Homebrew/cask/test/cask/cli/list_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/list_spec.rb
index 9acf37efee..49c06c5210 100644
--- a/Library/Homebrew/cask/test/cask/cli/list_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/list_spec.rb
@@ -1,16 +1,16 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::List do
it "lists the installed Casks in a pretty fashion" do
casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) }
casks.each do |c|
- TestHelper.install_with_caskfile(c)
+ InstallHelper.install_with_caskfile(c)
end
- lambda {
+ expect {
Hbc::CLI::List.run
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
local-caffeine
local-transmission
EOS
@@ -18,7 +18,7 @@ describe Hbc::CLI::List do
describe "lists versions" do
let(:casks) { ["local-caffeine", "local-transmission"] }
- let(:output) {
+ let(:expected_output) {
<<-EOS.undent
local-caffeine 1.2.3
local-transmission 2.61
@@ -26,19 +26,19 @@ describe Hbc::CLI::List do
}
before(:each) do
- casks.map(&Hbc.method(:load)).each(&TestHelper.method(:install_with_caskfile))
+ casks.map(&Hbc.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
end
it "of all installed Casks" do
- lambda {
+ expect {
Hbc::CLI::List.run("--versions")
- }.must_output(output)
+ }.to output(expected_output).to_stdout
end
it "of given Casks" do
- lambda {
+ expect {
Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission")
- }.must_output(output)
+ }.to output(expected_output).to_stdout
end
end
@@ -50,14 +50,10 @@ describe Hbc::CLI::List do
staged_path.mkpath
end
- after do
- caskroom_path.rmtree
- end
-
it "lists installed Casks without backing ruby files (due to renames or otherwise)" do
- lambda {
+ expect {
Hbc::CLI::List.run
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
ive-been-renamed (!)
EOS
end
@@ -69,15 +65,15 @@ describe Hbc::CLI::List do
let(:casks) { [caffeine, transmission] }
it "lists the installed files for those Casks" do
- casks.each(&TestHelper.method(:install_without_artifacts_with_caskfile))
+ casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile))
shutup do
Hbc::Artifact::App.new(transmission).install_phase
end
- lambda {
+ expect {
Hbc::CLI::List.run("local-transmission", "local-caffeine")
- }.must_output <<-EOS.undent
+ }.to output(<<-EOS.undent).to_stdout
==> Apps
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
==> Apps
diff --git a/Library/Homebrew/cask/test/cask/cli/options_test.rb b/Library/Homebrew/cask/spec/cask/cli/options_spec.rb
similarity index 69%
rename from Library/Homebrew/cask/test/cask/cli/options_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/options_spec.rb
index d49e7827b7..a4381213a6 100644
--- a/Library/Homebrew/cask/test/cask/cli/options_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/options_spec.rb
@@ -1,10 +1,10 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI do
it "supports setting the appdir" do
Hbc::CLI.process_options %w[help --appdir=/some/path/foo]
- Hbc.appdir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the appdir from ENV" do
@@ -12,13 +12,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.appdir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the prefpanedir" do
Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo]
- Hbc.prefpanedir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the prefpanedir from ENV" do
@@ -26,13 +26,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.prefpanedir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the qlplugindir" do
Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo]
- Hbc.qlplugindir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the qlplugindir from ENV" do
@@ -40,13 +40,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.qlplugindir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the colorpickerdir" do
Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo]
- Hbc.colorpickerdir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the colorpickerdir from ENV" do
@@ -54,13 +54,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.colorpickerdir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the dictionarydir" do
Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo]
- Hbc.dictionarydir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the dictionarydir from ENV" do
@@ -68,13 +68,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.dictionarydir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the fontdir" do
Hbc::CLI.process_options %w[help --fontdir=/some/path/foo]
- Hbc.fontdir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the fontdir from ENV" do
@@ -82,13 +82,13 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.fontdir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the servicedir" do
Hbc::CLI.process_options %w[help --servicedir=/some/path/foo]
- Hbc.servicedir.must_equal Pathname("/some/path/foo")
+ expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the servicedir from ENV" do
@@ -96,36 +96,36 @@ describe Hbc::CLI do
Hbc::CLI.process_options %w[help]
- Hbc.servicedir.must_equal Pathname("/some/path/bar")
+ expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
end
it "allows additional options to be passed through" do
rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux]
- Hbc.appdir.must_equal Pathname("/some/path/qux")
- rest.must_equal %w[edit foo --create]
+ expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
+ expect(rest).to eq(%w[edit foo --create])
end
describe "when a mandatory argument is missing" do
it "shows a user-friendly error message" do
- lambda {
+ expect {
Hbc::CLI.process_options %w[install -f]
- }.must_raise Hbc::CaskError
+ }.to raise_error(Hbc::CaskError)
end
end
describe "given an ambiguous option" do
it "shows a user-friendly error message" do
- lambda {
+ expect {
Hbc::CLI.process_options %w[edit -c]
- }.must_raise Hbc::CaskError
+ }.to raise_error(Hbc::CaskError)
end
end
describe "--debug" do
it "sets the Cask debug method to true" do
Hbc::CLI.process_options %w[help --debug]
- Hbc.debug.must_equal true
+ expect(Hbc.debug).to be true
Hbc.debug = false
end
end
@@ -133,12 +133,8 @@ describe Hbc::CLI do
describe "--help" do
it "sets the Cask help method to true" do
Hbc::CLI.process_options %w[foo --help]
- Hbc.help.must_equal true
+ expect(Hbc.help).to be true
Hbc.help = false
end
end
-
- after do
- ENV["HOMEBREW_CASK_OPTS"] = nil
- end
end
diff --git a/Library/Homebrew/cask/spec/cask/cli/reinstall_spec.rb b/Library/Homebrew/cask/spec/cask/cli/reinstall_spec.rb
new file mode 100644
index 0000000000..df83c53e28
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/cli/reinstall_spec.rb
@@ -0,0 +1,24 @@
+require "spec_helper"
+
+describe Hbc::CLI::Reinstall do
+ it "allows reinstalling a Cask" do
+ shutup do
+ Hbc::CLI::Install.run("local-transmission")
+ end
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+
+ shutup do
+ Hbc::CLI::Reinstall.run("local-transmission")
+ end
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ end
+
+ it "allows reinstalling a non installed Cask" do
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed
+
+ shutup do
+ Hbc::CLI::Reinstall.run("local-transmission")
+ end
+ expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ end
+end
diff --git a/Library/Homebrew/cask/spec/cask/cli/search_spec.rb b/Library/Homebrew/cask/spec/cask/cli/search_spec.rb
new file mode 100644
index 0000000000..fe669dd3e2
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/cli/search_spec.rb
@@ -0,0 +1,61 @@
+require "spec_helper"
+
+describe Hbc::CLI::Search do
+ it "lists the available Casks that match the search term" do
+ expect {
+ Hbc::CLI::Search.run("photoshop")
+ }.to output(<<-EOS.undent).to_stdout
+ ==> Partial matches
+ adobe-photoshop-cc
+ adobe-photoshop-lightroom
+ EOS
+ end
+
+ it "shows that there are no Casks matching a search term that did not result in anything" do
+ expect {
+ Hbc::CLI::Search.run("foo-bar-baz")
+ }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout
+ end
+
+ it "lists all available Casks with no search term" do
+ expect {
+ Hbc::CLI::Search.run
+ }.to output(/google-chrome/).to_stdout
+ end
+
+ it "ignores hyphens in search terms" do
+ expect {
+ Hbc::CLI::Search.run("goo-gle-chrome")
+ }.to output(/google-chrome/).to_stdout
+ end
+
+ it "ignores hyphens in Cask tokens" do
+ expect {
+ Hbc::CLI::Search.run("googlechrome")
+ }.to output(/google-chrome/).to_stdout
+ end
+
+ it "accepts multiple arguments" do
+ expect {
+ Hbc::CLI::Search.run("google chrome")
+ }.to output(/google-chrome/).to_stdout
+ end
+
+ it "accepts a regexp argument" do
+ expect {
+ Hbc::CLI::Search.run("/^google-c[a-z]rome$/")
+ }.to output("==> Regexp matches\ngoogle-chrome\n").to_stdout
+ end
+
+ it "Returns both exact and partial matches" do
+ expect {
+ Hbc::CLI::Search.run("mnemosyne")
+ }.to output(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/).to_stdout
+ end
+
+ it "does not search the Tap name" do
+ expect {
+ Hbc::CLI::Search.run("caskroom")
+ }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/cli/uninstall_test.rb b/Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
similarity index 71%
rename from Library/Homebrew/cask/test/cask/cli/uninstall_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
index 540909be39..be0aa31b6f 100644
--- a/Library/Homebrew/cask/test/cask/cli/uninstall_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
@@ -1,22 +1,22 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Uninstall do
it "shows an error when a bad Cask is provided" do
- lambda {
+ expect {
Hbc::CLI::Uninstall.run("notacask")
- }.must_raise Hbc::CaskUnavailableError
+ }.to raise_error(Hbc::CaskUnavailableError)
end
it "shows an error when a Cask is provided that's not installed" do
- lambda {
+ expect {
Hbc::CLI::Uninstall.run("anvil")
- }.must_raise Hbc::CaskNotInstalledError
+ }.to raise_error(Hbc::CaskNotInstalledError)
end
it "tries anyway on a non-present Cask when --force is given" do
- lambda do
+ expect {
Hbc::CLI::Uninstall.run("anvil", "--force")
- end # wont_raise
+ }.not_to raise_error
end
it "can uninstall and unlink multiple Casks at once" do
@@ -28,17 +28,17 @@ describe Hbc::CLI::Uninstall do
Hbc::Installer.new(transmission).install
end
- caffeine.must_be :installed?
- transmission.must_be :installed?
+ expect(caffeine).to be_installed
+ expect(transmission).to be_installed
shutup do
Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission")
end
- caffeine.wont_be :installed?
- Hbc.appdir.join("Transmission.app").wont_be :exist?
- transmission.wont_be :installed?
- Hbc.appdir.join("Caffeine.app").wont_be :exist?
+ expect(caffeine).not_to be_installed
+ expect(Hbc.appdir.join("Transmission.app")).not_to exist
+ expect(transmission).not_to be_installed
+ expect(Hbc.appdir.join("Caffeine.app")).not_to exist
end
describe "when multiple versions of a cask are installed" do
@@ -67,34 +67,29 @@ describe Hbc::CLI::Uninstall do
end
end
- after(:each) do
- caskroom_path.rmtree if caskroom_path.exist?
- end
-
it "uninstalls one version at a time" do
shutup do
Hbc::CLI::Uninstall.run("versioned-cask")
end
- caskroom_path.join(first_installed_version).must_be :exist?
- caskroom_path.join(last_installed_version).wont_be :exist?
- caskroom_path.must_be :exist?
+ expect(caskroom_path.join(first_installed_version)).to exist
+ expect(caskroom_path.join(last_installed_version)).not_to exist
+ expect(caskroom_path).to exist
shutup do
Hbc::CLI::Uninstall.run("versioned-cask")
end
- caskroom_path.join(first_installed_version).wont_be :exist?
- caskroom_path.wont_be :exist?
+ expect(caskroom_path.join(first_installed_version)).not_to exist
+ expect(caskroom_path).not_to exist
end
it "displays a message when versions remain installed" do
- out, err = capture_io do
- Hbc::CLI::Uninstall.run("versioned-cask")
- end
-
- out.must_match(/#{token} #{first_installed_version} is still installed./)
- err.must_be :empty?
+ expect {
+ expect {
+ Hbc::CLI::Uninstall.run("versioned-cask")
+ }.not_to output.to_stderr
+ }.to output(/#{token} #{first_installed_version} is still installed./).to_stdout
end
end
@@ -121,34 +116,29 @@ describe Hbc::CLI::Uninstall do
EOS
end
- after do
- app.rmtree if app.exist?
- caskroom_path.rmtree if caskroom_path.exist?
- end
-
it "can still uninstall those Casks" do
shutup do
Hbc::CLI::Uninstall.run("ive-been-renamed")
end
- app.wont_be :exist?
- caskroom_path.wont_be :exist?
+ expect(app).not_to exist
+ expect(caskroom_path).not_to exist
end
end
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Uninstall.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Uninstall.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/spec/cask/cli/version_spec.rb b/Library/Homebrew/cask/spec/cask/cli/version_spec.rb
new file mode 100644
index 0000000000..e6fcf48501
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/cli/version_spec.rb
@@ -0,0 +1,11 @@
+require "spec_helper"
+
+describe "brew cask --version" do
+ it "respects the --version argument" do
+ expect {
+ expect {
+ Hbc::CLI::NullCommand.new("--version").run
+ }.not_to output.to_stderr
+ }.to output(Hbc.full_version).to_stdout
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/cli/zap_test.rb b/Library/Homebrew/cask/spec/cask/cli/zap_spec.rb
similarity index 83%
rename from Library/Homebrew/cask/test/cask/cli/zap_test.rb
rename to Library/Homebrew/cask/spec/cask/cli/zap_spec.rb
index 0f2aa4f8e5..d26114567f 100644
--- a/Library/Homebrew/cask/test/cask/cli/zap_test.rb
+++ b/Library/Homebrew/cask/spec/cask/cli/zap_spec.rb
@@ -1,10 +1,10 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::CLI::Zap do
it "shows an error when a bad Cask is provided" do
- lambda {
+ expect {
Hbc::CLI::Zap.run("notacask")
- }.must_raise Hbc::CaskUnavailableError
+ }.to raise_error(Hbc::CaskUnavailableError)
end
it "can zap and unlink multiple Casks at once" do
@@ -16,18 +16,18 @@ describe Hbc::CLI::Zap do
Hbc::Installer.new(transmission).install
end
- caffeine.must_be :installed?
- transmission.must_be :installed?
+ expect(caffeine).to be_installed
+ expect(transmission).to be_installed
shutup do
Hbc::CLI::Zap.run("--notavalidoption",
"local-caffeine", "local-transmission")
end
- caffeine.wont_be :installed?
- Hbc.appdir.join("Transmission.app").wont_be :symlink?
- transmission.wont_be :installed?
- Hbc.appdir.join("Caffeine.app").wont_be :symlink?
+ expect(caffeine).not_to be_installed
+ expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink
+ expect(transmission).not_to be_installed
+ expect(Hbc.appdir.join("Transmission.app")).not_to be_a_symlink
end
# TODO: Explicit test that both zap and uninstall directives get dispatched.
@@ -59,17 +59,17 @@ describe Hbc::CLI::Zap do
describe "when no Cask is specified" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Zap.run
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
- lambda {
+ expect {
Hbc::CLI::Zap.run("--notavalidoption")
- }.must_raise Hbc::CaskUnspecifiedError
+ }.to raise_error(Hbc::CaskUnspecifiedError)
end
end
end
diff --git a/Library/Homebrew/cask/test/cask/container/dmg_test.rb b/Library/Homebrew/cask/spec/cask/container/dmg_spec.rb
similarity index 82%
rename from Library/Homebrew/cask/test/cask/container/dmg_test.rb
rename to Library/Homebrew/cask/spec/cask/container/dmg_spec.rb
index 67161c5802..af42d89b1e 100644
--- a/Library/Homebrew/cask/test/cask/container/dmg_test.rb
+++ b/Library/Homebrew/cask/spec/cask/container/dmg_spec.rb
@@ -1,7 +1,7 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Container::Dmg do
- describe "mount!" do
+ describe "#mount!" do
it "does not store nil mounts for dmgs with extra data" do
transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
@@ -13,7 +13,7 @@ describe Hbc::Container::Dmg do
begin
dmg.mount!
- dmg.mounts.wont_include nil
+ expect(dmg.mounts).not_to include nil
ensure
dmg.eject!
end
diff --git a/Library/Homebrew/cask/test/cask/container/naked_test.rb b/Library/Homebrew/cask/spec/cask/container/naked_spec.rb
similarity index 75%
rename from Library/Homebrew/cask/test/cask/container/naked_test.rb
rename to Library/Homebrew/cask/spec/cask/container/naked_spec.rb
index d40c16de5f..ee4102ecab 100644
--- a/Library/Homebrew/cask/test/cask/container/naked_test.rb
+++ b/Library/Homebrew/cask/spec/cask/container/naked_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Container::Naked do
it "saves files with spaces in them from uris with encoded spaces" do
@@ -13,8 +13,13 @@ describe Hbc::Container::Naked do
Hbc::FakeSystemCommand.stubs_command(expected_command)
container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand)
- container.extract
- Hbc::FakeSystemCommand.system_calls[expected_command].must_equal 1
+ expect {
+ shutup do
+ container.extract
+ end
+ }.not_to raise_error
+
+ expect(Hbc::FakeSystemCommand.system_calls[expected_command]).to eq(1)
end
end
diff --git a/Library/Homebrew/cask/spec/cask/depends_on_spec.rb b/Library/Homebrew/cask/spec/cask/depends_on_spec.rb
new file mode 100644
index 0000000000..078a2bce74
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/depends_on_spec.rb
@@ -0,0 +1,92 @@
+require "spec_helper"
+
+# TODO: this test should be named after the corresponding class, once
+# that class is abstracted from installer.rb
+describe "Satisfy Dependencies and Requirements" do
+ subject {
+ lambda do
+ shutup do
+ Hbc::Installer.new(cask).install
+ end
+ end
+ }
+
+ describe "depends_on cask" do
+ context "when depends_on cask is cyclic" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") }
+ it { is_expected.to raise_error(Hbc::CaskCyclicCaskDependencyError) }
+ end
+
+ context do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb") }
+ let(:dependency) { Hbc.load(cask.depends_on.cask.first) }
+
+ it "installs the dependency of a Cask and the Cask itself" do
+ expect(subject).not_to raise_error
+ expect(cask).to be_installed
+ expect(dependency).to be_installed
+ end
+ end
+ end
+
+ describe "depends_on macos" do
+ context "given an array" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-array.rb") }
+ it { is_expected.not_to raise_error }
+ end
+
+ context "given a comparisson" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb") }
+ it { is_expected.not_to raise_error }
+ end
+
+ context "given a string" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-string.rb") }
+ it { is_expected.not_to raise_error }
+ end
+
+ context "given a symbol" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-symbol.rb") }
+ it { is_expected.not_to raise_error }
+ end
+
+ context "when not satisfied" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-failure.rb") }
+ it { is_expected.to raise_error(Hbc::CaskError) }
+ end
+ end
+
+ describe "depends_on arch" do
+ context "when satisfied" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-arch.rb") }
+ it { is_expected.not_to raise_error }
+ end
+ end
+
+ describe "depends_on x11" do
+ before(:each) do
+ allow(MacOS::X11).to receive(:installed?).and_return(x11_installed)
+ end
+
+ context "when satisfied" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") }
+ let(:x11_installed) { true }
+
+ it { is_expected.not_to raise_error }
+ end
+
+ context "when not satisfied" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") }
+ let(:x11_installed) { false }
+
+ it { is_expected.to raise_error(Hbc::CaskX11DependencyError) }
+ end
+
+ context "when depends_on x11: false" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11-false.rb") }
+ let(:x11_installed) { false }
+
+ it { is_expected.not_to raise_error }
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/dsl/caveats_test.rb b/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb
similarity index 91%
rename from Library/Homebrew/cask/test/cask/dsl/caveats_test.rb
rename to Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb
index 37845e7c3d..777491d66e 100644
--- a/Library/Homebrew/cask/test/cask/dsl/caveats_test.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::DSL::Caveats do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
diff --git a/Library/Homebrew/cask/test/cask/dsl/postflight_test.rb b/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb
similarity index 93%
rename from Library/Homebrew/cask/test/cask/dsl/postflight_test.rb
rename to Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb
index b5b38102db..116a7c8a80 100644
--- a/Library/Homebrew/cask/test/cask/dsl/postflight_test.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::DSL::Postflight do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
diff --git a/Library/Homebrew/cask/test/cask/dsl/preflight_test.rb b/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb
similarity index 93%
rename from Library/Homebrew/cask/test/cask/dsl/preflight_test.rb
rename to Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb
index 555be7ed9f..90d2634dbb 100644
--- a/Library/Homebrew/cask/test/cask/dsl/preflight_test.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::DSL::Preflight do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
diff --git a/Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb b/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb
similarity index 92%
rename from Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb
rename to Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb
index ae4db979e5..4b7dd75574 100644
--- a/Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::DSL::UninstallPostflight do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
diff --git a/Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb b/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb
similarity index 93%
rename from Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb
rename to Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb
index f964b0098d..a4930e99e9 100644
--- a/Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb
@@ -1,4 +1,4 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::DSL::UninstallPreflight do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
diff --git a/Library/Homebrew/cask/spec/cask/dsl_spec.rb b/Library/Homebrew/cask/spec/cask/dsl_spec.rb
new file mode 100644
index 0000000000..99525cc205
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/dsl_spec.rb
@@ -0,0 +1,548 @@
+require "spec_helper"
+
+describe Hbc::DSL do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") }
+ let(:token) { "basic-cask" }
+
+ context "stanzas" do
+ it "lets you set url, homepage, and version" do
+ expect(cask.url.to_s).to eq("http://example.com/TestCask.dmg")
+ expect(cask.homepage).to eq("http://example.com/")
+ expect(cask.version.to_s).to eq("1.2.3")
+ end
+ end
+
+ describe "when a Cask includes an unknown method" do
+ let(:attempt_unknown_method) {
+ lambda do
+ Hbc::Cask.new("unexpected-method-cask") do
+ future_feature :not_yet_on_your_machine
+ end
+ end
+ }
+
+ it "prints a warning that it has encountered an unexpected method" do
+ expected = Regexp.compile(<<-EOS.undent.lines.map(&:chomp).join(""))
+ (?m)
+ Warning:
+ .*
+ Unexpected method 'future_feature' called on Cask unexpected-method-cask\\.
+ .*
+ https://github.com/caskroom/homebrew-cask/blob/master/doc/reporting_bugs/pre_bug_report.md
+ .*
+ https://github.com/caskroom/homebrew-cask#reporting-bugs
+ EOS
+
+ expect {
+ expect(attempt_unknown_method).not_to output.to_stdout
+ }.to output(expected).to_stderr
+ end
+
+ it "will simply warn, not throw an exception" do
+ expect {
+ shutup do
+ attempt_unknown_method.call
+ end
+ }.not_to raise_error
+ end
+ end
+
+ describe "header line" do
+ context "when invalid" do
+ let(:token) { "invalid/invalid-header-format" }
+ it "raises an error" do
+ expect { cask }.to raise_error(SyntaxError)
+ end
+ end
+
+ context "when token does not match the file name" do
+ let(:token) { "invalid/invalid-header-token-mismatch" }
+
+ it "raises an error" do
+ expect {
+ cask
+ }.to raise_error(Hbc::CaskTokenDoesNotMatchError, /Bad header line:.*does not match file name/)
+ end
+ end
+
+ context "when it contains no DSL version" do
+ let(:token) { "no-dsl-version" }
+
+ it "does not require a DSL version in the header" do
+ expect(cask.token).to eq("no-dsl-version")
+ expect(cask.url.to_s).to eq("http://example.com/TestCask.dmg")
+ expect(cask.homepage).to eq("http://example.com/")
+ expect(cask.version.to_s).to eq("1.2.3")
+ end
+ end
+
+ context "when it contains a deprecated DSL version" do
+ let(:token) { "with-dsl-version" }
+
+ it "may use deprecated DSL version hash syntax" do
+ allow(ENV).to receive(:[]).with("HOMEBREW_DEVELOPER").and_return(nil)
+
+ shutup do
+ expect(cask.token).to eq("with-dsl-version")
+ expect(cask.url.to_s).to eq("http://example.com/TestCask.dmg")
+ expect(cask.homepage).to eq("http://example.com/")
+ expect(cask.version.to_s).to eq("1.2.3")
+ end
+ end
+ end
+ end
+
+ describe "name stanza" do
+ it "lets you set the full name via a name stanza" do
+ cask = Hbc::Cask.new("name-cask") do
+ name "Proper Name"
+ end
+
+ expect(cask.name).to eq([
+ "Proper Name",
+ ])
+ end
+
+ it "Accepts an array value to the name stanza" do
+ cask = Hbc::Cask.new("array-name-cask") do
+ name ["Proper Name", "Alternate Name"]
+ end
+
+ expect(cask.name).to eq([
+ "Proper Name",
+ "Alternate Name",
+ ])
+ end
+
+ it "Accepts multiple name stanzas" do
+ cask = Hbc::Cask.new("multi-name-cask") do
+ name "Proper Name"
+ name "Alternate Name"
+ end
+
+ expect(cask.name).to eq([
+ "Proper Name",
+ "Alternate Name",
+ ])
+ end
+ end
+
+ describe "sha256 stanza" do
+ it "lets you set checksum via sha256" do
+ cask = Hbc::Cask.new("checksum-cask") do
+ sha256 "imasha2"
+ end
+
+ expect(cask.sha256).to eq("imasha2")
+ end
+ end
+
+ describe "language stanza" do
+ it "allows multilingual casks" do
+ cask = lambda do
+ Hbc::Cask.new("cask-with-apps") do
+ language "zh" do
+ sha256 "abc123"
+ "zh-CN"
+ end
+
+ language "en-US", default: true do
+ sha256 "xyz789"
+ "en-US"
+ end
+
+ url "https://example.org/#{language}.zip"
+ end
+ end
+
+ allow(MacOS).to receive(:languages).and_return(["zh"])
+ expect(cask.call.language).to eq("zh-CN")
+ expect(cask.call.sha256).to eq("abc123")
+ expect(cask.call.url.to_s).to eq("https://example.org/zh-CN.zip")
+
+ allow(MacOS).to receive(:languages).and_return(["zh-XX"])
+ expect(cask.call.language).to eq("zh-CN")
+ expect(cask.call.sha256).to eq("abc123")
+ expect(cask.call.url.to_s).to eq("https://example.org/zh-CN.zip")
+
+ allow(MacOS).to receive(:languages).and_return(["en"])
+ expect(cask.call.language).to eq("en-US")
+ expect(cask.call.sha256).to eq("xyz789")
+ expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip")
+
+ allow(MacOS).to receive(:languages).and_return(["xx-XX"])
+ expect(cask.call.language).to eq("en-US")
+ expect(cask.call.sha256).to eq("xyz789")
+ expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip")
+
+ allow(MacOS).to receive(:languages).and_return(["xx-XX", "zh", "en"])
+ expect(cask.call.language).to eq("zh-CN")
+ expect(cask.call.sha256).to eq("abc123")
+ expect(cask.call.url.to_s).to eq("https://example.org/zh-CN.zip")
+
+ allow(MacOS).to receive(:languages).and_return(["xx-XX", "en-US", "zh"])
+ expect(cask.call.language).to eq("en-US")
+ expect(cask.call.sha256).to eq("xyz789")
+ expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip")
+ end
+ end
+
+ describe "app stanza" do
+ it "allows you to specify app stanzas" do
+ cask = Hbc::Cask.new("cask-with-apps") do
+ app "Foo.app"
+ app "Bar.app"
+ end
+
+ expect(Array(cask.artifacts[:app])).to eq([["Foo.app"], ["Bar.app"]])
+ end
+
+ it "allow app stanzas to be empty" do
+ cask = Hbc::Cask.new("cask-with-no-apps")
+ expect(Array(cask.artifacts[:app])).to eq([])
+ end
+ end
+
+ describe "caveats stanza" do
+ it "allows caveats to be specified via a method define" do
+ cask = Hbc::Cask.new("plain-cask")
+
+ expect(cask.caveats).to be_empty
+
+ cask = Hbc::Cask.new("cask-with-caveats") do
+ def caveats; <<-EOS.undent
+ When you install this Cask, you probably want to know this.
+ EOS
+ end
+ end
+
+ expect(cask.caveats).to eq("When you install this Cask, you probably want to know this.\n")
+ end
+ end
+
+ describe "pkg stanza" do
+ it "allows installable pkgs to be specified" do
+ cask = Hbc::Cask.new("cask-with-pkgs") do
+ pkg "Foo.pkg"
+ pkg "Bar.pkg"
+ end
+
+ expect(Array(cask.artifacts[:pkg])).to eq([["Foo.pkg"], ["Bar.pkg"]])
+ end
+ end
+
+ describe "url stanza" do
+ let(:token) { "invalid/invalid-two-url" }
+
+ it "prevents defining multiple urls" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'url' stanza may only appear once/)
+ end
+ end
+
+ describe "homepage stanza" do
+ let(:token) { "invalid/invalid-two-homepage" }
+
+ it "prevents defining multiple homepages" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'homepage' stanza may only appear once/)
+ end
+ end
+
+ describe "version stanza" do
+ let(:token) { "invalid/invalid-two-version" }
+ it "prevents defining multiple versions" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'version' stanza may only appear once/)
+ end
+ end
+
+ describe "appcast stanza" do
+ let(:token) { "with-appcast" }
+
+ it "allows appcasts to be specified" do
+ expect(cask.appcast.to_s).to match(/^http/)
+ end
+
+ context "when multiple appcasts are defined" do
+ let(:token) { "invalid/invalid-appcast-multiple" }
+
+ it "raises an error" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'appcast' stanza may only appear once/)
+ end
+ end
+
+ context "when appcast URL is invalid" do
+ let(:token) { "invalid/invalid-appcast-url" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "GPG stanza" do
+ context "valid" do
+ let(:token) { "with-gpg" }
+
+ it "is allowed to be specified" do
+ expect(cask.gpg.to_s).to match(/\S/)
+ end
+ end
+
+ context "with :key_url" do
+ let(:token) { "with-gpg-key-url" }
+ it "is allowed to be specified" do
+ expect(cask.gpg.to_s).to match(/\S/)
+ end
+ end
+
+ context "specifying mmultiple times" do
+ let(:token) { "invalid/invalid-gpg-multiple-stanzas" }
+
+ it "is not allowed" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'gpg' stanza may only appear once/)
+ end
+ end
+
+ context "missing GPG key parameters" do
+ let(:token) { "invalid/invalid-gpg-missing-key" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'gpg' stanza must include exactly one/)
+ end
+ end
+
+ context "conflicting GPG key parameters" do
+ let(:token) { "invalid/invalid-gpg-conflicting-keys" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'gpg' stanza must include exactly one/)
+ end
+ end
+
+ context "invalid GPG signature URLs" do
+ let(:token) { "invalid/invalid-gpg-signature-url" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+
+ context "invalid GPG key URLs" do
+ let(:token) { "invalid/invalid-gpg-key-url" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+
+ context "invalid GPG key IDs" do
+ let(:token) { "invalid/invalid-gpg-key-id" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+
+ context "GPG parameter is unknown" do
+ let(:token) { "invalid/invalid-gpg-parameter" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "depends_on stanza" do
+ let(:token) { "invalid/invalid-depends-on-key" }
+
+ it "refuses to load with an invalid depends_on key" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+
+ describe "depends_on formula" do
+ context "with one Formula" do
+ let(:token) { "with-depends-on-formula" }
+
+ it "allows depends_on formula to be specified" do
+ expect(cask.depends_on.formula).not_to be nil
+ end
+ end
+
+ context "with multiple Formulae" do
+ let(:token) { "with-depends-on-formula-multiple" }
+
+ it "allows multiple depends_on formula to be specified" do
+ expect(cask.depends_on.formula).not_to be nil
+ end
+ end
+ end
+
+ describe "depends_on cask" do
+ context "specifying one" do
+ let(:token) { "with-depends-on-cask" }
+ it "is allowed" do
+ expect(cask.depends_on.cask).not_to be nil
+ end
+ end
+
+ context "specifying multiple" do
+ let(:token) { "with-depends-on-cask-multiple" }
+
+ it "is allowed" do
+ expect(cask.depends_on.cask).not_to be nil
+ end
+ end
+ end
+
+ describe "depends_on macos" do
+ context "valid" do
+ let(:token) { "with-depends-on-macos-string" }
+
+ it "allows depends_on macos to be specified" do
+ expect(cask.depends_on.macos).not_to be nil
+ end
+ end
+
+ context "invalid depends_on macos value" do
+ let(:token) { "invalid/invalid-depends-on-macos-bad-release" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+
+ context "conflicting depends_on macos forms" do
+ let(:token) { "invalid/invalid-depends-on-macos-conflicting-forms" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "depends_on arch" do
+ context "valid" do
+ let(:token) { "with-depends-on-arch" }
+
+ it "is allowed to be specified" do
+ expect(cask.depends_on.arch).not_to be nil
+ end
+ end
+
+ context "invalid depends_on arch value" do
+ let(:token) { "invalid/invalid-depends-on-arch-value" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "depends_on x11" do
+ context "valid" do
+ let(:token) { "with-depends-on-x11" }
+
+ it "is allowed to be specified" do
+ expect(cask.depends_on.x11).not_to be nil
+ end
+ end
+
+ context "invalid depends_on x11 value" do
+ let(:token) { "invalid/invalid-depends-on-x11-value" }
+
+ it "refuses to load" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "conflicts_with stanza" do
+ context "valid" do
+ let(:token) { "with-conflicts-with" }
+
+ it "allows conflicts_with stanza to be specified" do
+ expect(cask.conflicts_with.formula).not_to be nil
+ end
+ end
+
+ context "invalid conflicts_with key" do
+ let(:token) { "invalid/invalid-conflicts-with-key" }
+
+ it "refuses to load invalid conflicts_with key" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError)
+ end
+ end
+ end
+
+ describe "installer stanza" do
+ context "script" do
+ let(:token) { "with-installer-script" }
+
+ it "allows installer script to be specified" do
+ expect(cask.artifacts[:installer].first.script[:executable]).to eq("/usr/bin/true")
+ expect(cask.artifacts[:installer].first.script[:args]).to eq(["--flag"])
+ expect(cask.artifacts[:installer].to_a[1].script[:executable]).to eq("/usr/bin/false")
+ expect(cask.artifacts[:installer].to_a[1].script[:args]).to eq(["--flag"])
+ end
+ end
+
+ context "manual" do
+ let(:token) { "with-installer-manual" }
+
+ it "allows installer manual to be specified" do
+ expect(cask.artifacts[:installer].first.manual).to eq("Caffeine.app")
+ end
+ end
+ end
+
+ describe "stage_only stanza" do
+ context "when there is no other activatable artifact" do
+ let(:token) { "stage-only" }
+
+ it "allows stage_only stanza to be specified" do
+ expect(cask.artifacts[:stage_only].first).to eq([true])
+ end
+ end
+
+ context "when there is are activatable artifacts" do
+ let(:token) { "invalid/invalid-stage-only-conflict" }
+
+ it "prevents specifying stage_only" do
+ expect { cask }.to raise_error(Hbc::CaskInvalidError, /'stage_only' must be the only activatable artifact/)
+ end
+ end
+ end
+
+ describe "auto_updates stanza" do
+ let(:token) { "auto-updates" }
+
+ it "allows auto_updates stanza to be specified" do
+ expect(cask.auto_updates).to be true
+ end
+ end
+
+ describe "appdir" do
+ context "interpolation of the appdir in stanzas" do
+ let(:token) { "appdir-interpolation" }
+
+ it "is allowed" do
+ expect(cask.artifacts[:binary].first).to eq(["#{Hbc.appdir}/some/path"])
+ end
+ end
+
+ it "does not include a trailing slash" do
+ begin
+ original_appdir = Hbc.appdir
+ Hbc.appdir = "#{original_appdir}/"
+
+ cask = Hbc::Cask.new("appdir-trailing-slash") do
+ binary "#{appdir}/some/path"
+ end
+
+ expect(cask.artifacts[:binary].first).to eq(["#{original_appdir}/some/path"])
+ ensure
+ Hbc.appdir = original_appdir
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/installer_test.rb b/Library/Homebrew/cask/spec/cask/installer_spec.rb
similarity index 73%
rename from Library/Homebrew/cask/test/cask/installer_test.rb
rename to Library/Homebrew/cask/spec/cask/installer_spec.rb
index 17629dce2e..c0148c3874 100644
--- a/Library/Homebrew/cask/test/cask/installer_test.rb
+++ b/Library/Homebrew/cask/spec/cask/installer_spec.rb
@@ -1,9 +1,9 @@
-require "test_helper"
+require "spec_helper"
describe Hbc::Installer do
describe "install" do
let(:empty_depends_on_stub) {
- stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil)
+ double(formula: [], cask: [], macos: nil, arch: nil, x11: nil)
}
it "downloads and installs a nice fresh Cask" do
@@ -13,8 +13,8 @@ describe Hbc::Installer do
Hbc::Installer.new(caffeine).install
end
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).must_be :directory?
- expect(Hbc.appdir.join("Caffeine.app")).must_be :directory?
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).to be_a_directory
+ expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory
end
it "works with dmg-based Casks" do
@@ -24,8 +24,8 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-dmg", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-dmg", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with tar-gz-based Casks" do
@@ -35,22 +35,22 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-tar-gz", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-tar-gz", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with cab-based Casks" do
skip("cabextract not installed") if which("cabextract").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-cab.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-cab", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-cab", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with Adobe AIR-based Casks" do
@@ -61,22 +61,21 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-air", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container.app")).must_be :directory?
+ expect(Hbc.caskroom.join("container-air", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container.app")).to be_a_directory
end
it "works with 7z-based Casks" do
skip("unar not installed") if which("unar").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-7z.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-7z", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-7z", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with xar-based Casks" do
@@ -86,36 +85,34 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-xar", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-xar", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with Stuffit-based Casks" do
skip("unar not installed") if which("unar").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-sit.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-sit", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-sit", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with RAR-based Casks" do
skip("unar not installed") if which("unar").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-rar.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-rar", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-rar", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with pure bzip2-based Casks" do
@@ -125,8 +122,8 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-bzip2", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container-bzip2--#{asset.version}")).must_be :file?
+ expect(Hbc.caskroom.join("container-bzip2", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container-bzip2--#{asset.version}")).to be_a_file
end
it "works with pure gzip-based Casks" do
@@ -136,36 +133,34 @@ describe Hbc::Installer do
Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-gzip", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container")).must_be :file?
+ expect(Hbc.caskroom.join("container-gzip", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container")).to be_a_file
end
it "works with pure xz-based Casks" do
skip("unxz not installed") if which("unxz").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-xz.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-xz", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container-xz--#{asset.version}")).must_be :file?
+ expect(Hbc.caskroom.join("container-xz", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container-xz--#{asset.version}")).to be_a_file
end
it "works with lzma-based Casks" do
skip("unlzma not installed") if which("unlzma").nil?
asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-lzma.rb")
- asset.stub :depends_on, empty_depends_on_stub do
- shutup do
- Hbc::Installer.new(asset).install
- end
+ allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub)
+ shutup do
+ Hbc::Installer.new(asset).install
end
- expect(Hbc.caskroom.join("container-lzma", asset.version)).must_be :directory?
- expect(Hbc.appdir.join("container-lzma--#{asset.version}")).must_be :file?
+ expect(Hbc.caskroom.join("container-lzma", asset.version)).to be_a_directory
+ expect(Hbc.appdir.join("container-lzma--#{asset.version}")).to be_a_file
end
it "blows up on a bad checksum" do
@@ -174,7 +169,7 @@ describe Hbc::Installer do
shutup do
Hbc::Installer.new(bad_checksum).install
end
- }.must_raise(Hbc::CaskSha256MismatchError)
+ }.to raise_error(Hbc::CaskSha256MismatchError)
end
it "blows up on a missing checksum" do
@@ -183,7 +178,7 @@ describe Hbc::Installer do
shutup do
Hbc::Installer.new(missing_checksum).install
end
- }.must_raise(Hbc::CaskSha256MissingError)
+ }.to raise_error(Hbc::CaskSha256MissingError)
end
it "installs fine if sha256 :no_check is used" do
@@ -193,14 +188,14 @@ describe Hbc::Installer do
Hbc::Installer.new(no_checksum).install
end
- expect(no_checksum).must_be :installed?
+ expect(no_checksum).to be_installed
end
it "fails to install if sha256 :no_check is used with --require-sha" do
no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb")
expect {
Hbc::Installer.new(no_checksum, require_sha: true).install
- }.must_raise(Hbc::CaskNoShasumError)
+ }.to raise_error(Hbc::CaskNoShasumError)
end
it "installs fine if sha256 :no_check is used with --require-sha and --force" do
@@ -210,7 +205,7 @@ describe Hbc::Installer do
Hbc::Installer.new(no_checksum, require_sha: true, force: true).install
end
- expect(no_checksum).must_be :installed?
+ expect(no_checksum).to be_installed
end
it "prints caveats if they're present" do
@@ -218,9 +213,9 @@ describe Hbc::Installer do
expect {
Hbc::Installer.new(with_caveats).install
- }.must_output(/Here are some things you might want to know/)
+ }.to output(/Here are some things you might want to know/).to_stdout
- expect(with_caveats).must_be :installed?
+ expect(with_caveats).to be_installed
end
it "prints installer :manual instructions when present" do
@@ -228,9 +223,9 @@ describe Hbc::Installer do
expect {
Hbc::Installer.new(with_installer_manual).install
- }.must_output(/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')}'/)
+ }.to output(/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')}'/).to_stdout
- expect(with_installer_manual).must_be :installed?
+ expect(with_installer_manual).to be_installed
end
it "does not extract __MACOSX directories from zips" do
@@ -240,13 +235,13 @@ describe Hbc::Installer do
Hbc::Installer.new(with_macosx_dir).install
end
- expect(with_macosx_dir.staged_path.join("__MACOSX")).wont_be :directory?
+ expect(with_macosx_dir.staged_path.join("__MACOSX")).not_to be_a_directory
end
it "installer method raises an exception when already-installed Casks which auto-update are attempted" do
with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb")
- expect(with_auto_updates).wont_be :installed?
+ expect(with_auto_updates).not_to be_installed
installer = Hbc::Installer.new(with_auto_updates)
@@ -256,28 +251,30 @@ describe Hbc::Installer do
expect {
installer.install
- }.must_raise(Hbc::CaskAlreadyInstalledAutoUpdatesError)
+ }.to raise_error(Hbc::CaskAlreadyInstalledAutoUpdatesError)
end
it "allows already-installed Casks which auto-update to be installed if force is provided" do
with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb")
- expect(with_auto_updates).wont_be :installed?
+ expect(with_auto_updates).not_to be_installed
shutup do
Hbc::Installer.new(with_auto_updates).install
end
- shutup do
- Hbc::Installer.new(with_auto_updates, force: true).install
- end # wont_raise
+ expect {
+ shutup do
+ Hbc::Installer.new(with_auto_updates, force: true).install
+ end
+ }.not_to raise_error
end
# unlike the CLI, the internal interface throws exception on double-install
it "installer method raises an exception when already-installed Casks are attempted" do
transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
- expect(transmission).wont_be :installed?
+ expect(transmission).not_to be_installed
installer = Hbc::Installer.new(transmission)
@@ -287,13 +284,13 @@ describe Hbc::Installer do
expect {
installer.install
- }.must_raise(Hbc::CaskAlreadyInstalledError)
+ }.to raise_error(Hbc::CaskAlreadyInstalledError)
end
it "allows already-installed Casks to be installed if force is provided" do
transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
- expect(transmission).wont_be :installed?
+ expect(transmission).not_to be_installed
shutup do
Hbc::Installer.new(transmission).install
@@ -311,7 +308,7 @@ describe Hbc::Installer do
Hbc::Installer.new(naked_pkg).install
end
- expect(Hbc.caskroom.join("container-pkg", naked_pkg.version, "container.pkg")).must_be :file?
+ expect(Hbc.caskroom.join("container-pkg", naked_pkg.version, "container.pkg")).to be_a_file
end
it "works properly with an overridden container :type" do
@@ -321,7 +318,7 @@ describe Hbc::Installer do
Hbc::Installer.new(naked_executable).install
end
- expect(Hbc.caskroom.join("naked-executable", naked_executable.version, "naked_executable")).must_be :file?
+ expect(Hbc.caskroom.join("naked-executable", naked_executable.version, "naked_executable")).to be_a_file
end
it "works fine with a nested container" do
@@ -331,7 +328,7 @@ describe Hbc::Installer do
Hbc::Installer.new(nested_app).install
end
- expect(Hbc.appdir.join("MyNestedApp.app")).must_be :directory?
+ expect(Hbc.appdir.join("MyNestedApp.app")).to be_a_directory
end
it "generates and finds a timestamped metadata directory for an installed Cask" do
@@ -342,8 +339,8 @@ describe Hbc::Installer do
end
m_path = caffeine.metadata_path(:now, true)
- expect(caffeine.metadata_path(:now, false)).must_equal(m_path)
- expect(caffeine.metadata_path(:latest)).must_equal(m_path)
+ expect(caffeine.metadata_path(:now, false)).to eq(m_path)
+ expect(caffeine.metadata_path(:latest)).to eq(m_path)
end
it "generates and finds a metadata subdirectory for an installed Cask" do
@@ -355,8 +352,8 @@ describe Hbc::Installer do
subdir_name = "Casks"
m_subdir = caffeine.metadata_subdir(subdir_name, :now, true)
- expect(caffeine.metadata_subdir(subdir_name, :now, false)).must_equal(m_subdir)
- expect(caffeine.metadata_subdir(subdir_name, :latest)).must_equal(m_subdir)
+ expect(caffeine.metadata_subdir(subdir_name, :now, false)).to eq(m_subdir)
+ expect(caffeine.metadata_subdir(subdir_name, :latest)).to eq(m_subdir)
end
end
@@ -370,9 +367,9 @@ describe Hbc::Installer do
installer.uninstall
end
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app")).wont_be :directory?
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory?
- expect(Hbc.caskroom.join("local-caffeine")).wont_be :directory?
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app")).not_to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine")).not_to be_a_directory
end
it "uninstalls all versions if force is set" do
@@ -383,19 +380,19 @@ describe Hbc::Installer do
Hbc::Installer.new(caffeine).install
end
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).must_be :directory?
- expect(Hbc.caskroom.join("local-caffeine", mutated_version)).wont_be :directory?
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine", mutated_version)).not_to be_a_directory
FileUtils.mv(Hbc.caskroom.join("local-caffeine", caffeine.version), Hbc.caskroom.join("local-caffeine", mutated_version))
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory?
- expect(Hbc.caskroom.join("local-caffeine", mutated_version)).must_be :directory?
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine", mutated_version)).to be_a_directory
shutup do
Hbc::Installer.new(caffeine, force: true).uninstall
end
- expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory?
- expect(Hbc.caskroom.join("local-caffeine", mutated_version)).wont_be :directory?
- expect(Hbc.caskroom.join("local-caffeine")).wont_be :directory?
+ expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine", mutated_version)).not_to be_a_directory
+ expect(Hbc.caskroom.join("local-caffeine")).not_to be_a_directory
end
end
end
diff --git a/Library/Homebrew/cask/spec/cask/pkg_spec.rb b/Library/Homebrew/cask/spec/cask/pkg_spec.rb
new file mode 100644
index 0000000000..2f0ba0839c
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/pkg_spec.rb
@@ -0,0 +1,114 @@
+require "spec_helper"
+
+describe Hbc::Pkg do
+ describe "uninstall" do
+ let(:fake_system_command) { Hbc::NeverSudoSystemCommand }
+ let(:empty_response) { double(stdout: "") }
+ let(:pkg) { described_class.new("my.fake.pkg", fake_system_command) }
+
+ it "removes files and dirs referenced by the pkg" do
+ some_files = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) }
+ allow(pkg).to receive(:pkgutil_bom_files).and_return(some_files)
+
+ some_specials = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) }
+ allow(pkg).to receive(:pkgutil_bom_specials).and_return(some_specials)
+
+ some_dirs = Array.new(3) { Pathname.new(Dir.mktmpdir) }
+ allow(pkg).to receive(:pkgutil_bom_dirs).and_return(some_dirs)
+
+ allow(pkg).to receive(:forget)
+
+ pkg.uninstall
+
+ some_files.each do |file|
+ expect(file).not_to exist
+ end
+
+ some_dirs.each do |dir|
+ expect(dir).not_to exist
+ end
+ end
+
+ context "pkgutil" do
+ let(:fake_system_command) { class_double(Hbc::SystemCommand) }
+
+ it "forgets the pkg" do
+ allow(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/pkgutil",
+ args: ["--only-files", "--files", "my.fake.pkg"]
+ ).and_return(empty_response)
+
+ allow(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/pkgutil",
+ args: ["--only-dirs", "--files", "my.fake.pkg"]
+ ).and_return(empty_response)
+
+ allow(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/pkgutil",
+ args: ["--files", "my.fake.pkg"]
+ ).and_return(empty_response)
+
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/pkgutil",
+ args: ["--forget", "my.fake.pkg"],
+ sudo: true
+ )
+
+ pkg.uninstall
+ end
+ end
+
+ it "removes broken symlinks" do
+ fake_dir = Pathname.new(Dir.mktmpdir)
+ fake_file = fake_dir.join("ima_file").tap { |path| FileUtils.touch(path) }
+
+ intact_symlink = fake_dir.join("intact_symlink").tap { |path| path.make_symlink(fake_file) }
+ broken_symlink = fake_dir.join("broken_symlink").tap { |path| path.make_symlink("im_nota_file") }
+
+ allow(pkg).to receive(:pkgutil_bom_specials).and_return([])
+ allow(pkg).to receive(:pkgutil_bom_files).and_return([])
+ allow(pkg).to receive(:pkgutil_bom_dirs).and_return([fake_dir])
+ allow(pkg).to receive(:forget)
+
+ pkg.uninstall
+
+ expect(intact_symlink).to exist
+ expect(broken_symlink).not_to exist
+ expect(fake_dir).to exist
+ end
+
+ it "removes files incorrectly reportes as directories" do
+ fake_dir = Pathname.new(Dir.mktmpdir)
+ fake_file = fake_dir.join("ima_file_pretending_to_be_a_dir").tap { |path| FileUtils.touch(path) }
+
+ allow(pkg).to receive(:pkgutil_bom_specials).and_return([])
+ allow(pkg).to receive(:pkgutil_bom_files).and_return([])
+ allow(pkg).to receive(:pkgutil_bom_dirs).and_return([fake_file, fake_dir])
+ allow(pkg).to receive(:forget)
+
+ pkg.uninstall
+
+ expect(fake_file).not_to exist
+ expect(fake_dir).not_to exist
+ end
+
+ it "snags permissions on ornery dirs, but returns them afterwards" do
+ fake_dir = Pathname.new(Dir.mktmpdir)
+ fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) }
+ fake_dir.chmod(0000)
+
+ allow(pkg).to receive(:pkgutil_bom_specials).and_return([])
+ allow(pkg).to receive(:pkgutil_bom_files).and_return([fake_file])
+ allow(pkg).to receive(:pkgutil_bom_dirs).and_return([fake_dir])
+ allow(pkg).to receive(:forget)
+
+ shutup do
+ pkg.uninstall
+ end
+
+ expect(fake_dir).to be_a_directory
+ expect(fake_file).not_to be_a_file
+ expect((fake_dir.stat.mode % 01000).to_s(8)).to eq("0")
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/spec/cask/scopes_spec.rb b/Library/Homebrew/cask/spec/cask/scopes_spec.rb
index 12c1a697f7..abf4b6401b 100644
--- a/Library/Homebrew/cask/spec/cask/scopes_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/scopes_spec.rb
@@ -1,39 +1,31 @@
describe Hbc::Scopes do
describe "installed" do
- let(:fake_caskroom) { Pathname(Dir.mktmpdir) }
-
- before do
- allow(Hbc).to receive(:caskroom) { fake_caskroom }
- end
-
- after do
- fake_caskroom.rmtree
- end
-
it "returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom" do
allow(Hbc).to receive(:load) { |token| "loaded-#{token}" }
- fake_caskroom.join("cask-bar").mkdir
- fake_caskroom.join("cask-foo").mkdir
+ Hbc.caskroom.join("cask-bar").mkpath
+ Hbc.caskroom.join("cask-foo").mkpath
installed_casks = Hbc.installed
expect(Hbc).to have_received(:load).with("cask-bar")
expect(Hbc).to have_received(:load).with("cask-foo")
- expect(installed_casks).to eq(%w[
- loaded-cask-bar
- loaded-cask-foo
- ])
+ expect(installed_casks).to eq(
+ %w[
+ loaded-cask-bar
+ loaded-cask-foo
+ ]
+ )
end
it "optimizes performance by resolving to a fully qualified path before calling Hbc.load" do
- fake_tapped_cask_dir = Pathname(Dir.mktmpdir).join("Casks")
+ fake_tapped_cask_dir = Pathname.new(Dir.mktmpdir).join("Casks")
absolute_path_to_cask = fake_tapped_cask_dir.join("some-cask.rb")
allow(Hbc).to receive(:load)
allow(Hbc).to receive(:all_tapped_cask_dirs) { [fake_tapped_cask_dir] }
- fake_caskroom.join("some-cask").mkdir
+ Hbc.caskroom.join("some-cask").mkdir
fake_tapped_cask_dir.mkdir
FileUtils.touch(absolute_path_to_cask)
diff --git a/Library/Homebrew/cask/test/cask/staged_test.rb b/Library/Homebrew/cask/spec/cask/staged_spec.rb
similarity index 57%
rename from Library/Homebrew/cask/test/cask/staged_test.rb
rename to Library/Homebrew/cask/spec/cask/staged_spec.rb
index 2b601a6aed..10f1cbb473 100644
--- a/Library/Homebrew/cask/test/cask/staged_test.rb
+++ b/Library/Homebrew/cask/spec/cask/staged_spec.rb
@@ -1,18 +1,18 @@
-require "test_helper"
+require "spec_helper"
# TODO: this test should be named after the corresponding class, once
# that class is abstracted from installer.rb. It makes little sense
# to be invoking bundle_identifier off of the installer instance.
describe "Operations on staged Casks" do
describe "bundle ID" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") }
+ let(:installer) { Hbc::Installer.new(cask) }
it "fetches the bundle ID from a staged cask" do
- transmission_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
- tr_installer = Hbc::Installer.new(transmission_cask)
-
shutup do
- tr_installer.install
+ installer.install
end
- tr_installer.bundle_identifier.must_equal("org.m0k.transmission")
+
+ expect(installer.bundle_identifier).to eq("org.m0k.transmission")
end
end
end
diff --git a/Library/Homebrew/cask/spec/cask/url_checker_spec.rb b/Library/Homebrew/cask/spec/cask/url_checker_spec.rb
new file mode 100644
index 0000000000..3b46bc587e
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/url_checker_spec.rb
@@ -0,0 +1,44 @@
+require "spec_helper"
+
+describe Hbc::UrlChecker do
+ describe "request processing" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:checker) { Hbc::UrlChecker.new(cask) }
+
+ before(:each) do
+ allow(Hbc::Fetcher).to receive(:head).and_return(response)
+ checker.run
+ end
+
+ context "with an empty response" do
+ let(:response) { "" }
+
+ it "adds an error" do
+ expect(checker.errors).to include("timeout while requesting #{cask.url}")
+ end
+ end
+
+ context "with a valid http response" do
+ let(:response) {
+ <<-EOS.undent
+ HTTP/1.1 200 OK
+ Content-Type: application/x-apple-diskimage
+ ETag: "b4208f3e84967be4b078ecaa03fba941"
+ Content-Length: 23726161
+ Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT
+ EOS
+ }
+
+ it "properly populates the response code and headers" do
+ expect(checker.errors).to be_empty
+ expect(checker.response_status).to eq("HTTP/1.1 200 OK")
+ expect(checker.headers).to eq(
+ "Content-Type" => "application/x-apple-diskimage",
+ "ETag" => '"b4208f3e84967be4b078ecaa03fba941"',
+ "Content-Length" => "23726161",
+ "Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT"
+ )
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/spec/plist/parser_spec.rb b/Library/Homebrew/cask/spec/plist/parser_spec.rb
new file mode 100644
index 0000000000..9d4a59fdc0
--- /dev/null
+++ b/Library/Homebrew/cask/spec/plist/parser_spec.rb
@@ -0,0 +1,75 @@
+require "spec_helper"
+
+describe Plist do
+ subject { described_class.parse_xml(input) }
+
+ describe "::parse_xml" do
+ context "given a hdiutil output as input" do
+ let(:input) {
+ <<-EOS.undent
+
+
+
+
+ system-entities
+
+
+ content-hint
+ Apple_partition_map
+ dev-entry
+ /dev/disk3s1
+ potentially-mountable
+
+ unmapped-content-hint
+ Apple_partition_map
+
+
+ content-hint
+ Apple_partition_scheme
+ dev-entry
+ /dev/disk3
+ potentially-mountable
+
+ unmapped-content-hint
+ Apple_partition_scheme
+
+
+ content-hint
+ Apple_HFS
+ dev-entry
+ /dev/disk3s2
+ mount-point
+ /private/tmp/dmg.BhfS2g
+ potentially-mountable
+
+ unmapped-content-hint
+ Apple_HFS
+ volume-kind
+ hfs
+
+
+
+
+ EOS
+ }
+
+ it "successfully parses it" do
+ expect(subject.keys).to eq(["system-entities"])
+ expect(subject["system-entities"].length).to eq(3)
+ expect(subject["system-entities"].map { |e| e["dev-entry"] }).to eq(
+ %w[
+ /dev/disk3s1
+ /dev/disk3
+ /dev/disk3s2
+ ]
+ )
+ end
+ end
+
+ context "given an empty input" do
+ let(:input) { "" }
+
+ it { is_expected.to be_nil }
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb
index eefee3d60e..ea6a87f417 100644
--- a/Library/Homebrew/cask/spec/spec_helper.rb
+++ b/Library/Homebrew/cask/spec/spec_helper.rb
@@ -17,7 +17,7 @@ $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
require "test/support/helper/shutup"
-Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require))
+Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require))
require "hbc"
@@ -31,7 +31,39 @@ Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
end
+# pretend that the caskroom/cask Tap is installed
+FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path
+
+HOMEBREW_CASK_DIRS = [
+ :appdir,
+ :caskroom,
+ :prefpanedir,
+ :qlplugindir,
+ :servicedir,
+ :binarydir,
+].freeze
+
RSpec.configure do |config|
config.order = :random
config.include(Test::Helper::Shutup)
+ config.around(:each) do |example|
+ begin
+ @__dirs = HOMEBREW_CASK_DIRS.map { |dir|
+ Pathname.new(TEST_TMPDIR).join(dir.to_s).tap { |path|
+ path.mkpath
+ Hbc.public_send("#{dir}=", path)
+ }
+ }
+
+ @__argv = ARGV.dup
+ @__env = ENV.to_hash # dup doesn't work on ENV
+
+ example.run
+ ensure
+ ARGV.replace(@__argv)
+ ENV.replace(@__env)
+
+ FileUtils.rm_rf @__dirs.map(&:children)
+ end
+ end
end
diff --git a/Library/Homebrew/cask/test/support/fake_system_command.rb b/Library/Homebrew/cask/spec/support/fake_system_command.rb
similarity index 87%
rename from Library/Homebrew/cask/test/support/fake_system_command.rb
rename to Library/Homebrew/cask/spec/support/fake_system_command.rb
index 97efd0761a..b9390d4821 100644
--- a/Library/Homebrew/cask/test/support/fake_system_command.rb
+++ b/Library/Homebrew/cask/spec/support/fake_system_command.rb
@@ -1,3 +1,7 @@
+def sudo(*args)
+ %w[/usr/bin/sudo -E --] + args.flatten
+end
+
module Hbc
class FakeSystemCommand
def self.responses
@@ -42,6 +46,7 @@ module Hbc
def self.run(command_string, options = {})
command = Hbc::SystemCommand.new(command_string, options).command
+ puts command
unless responses.key?(command)
raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}")
end
@@ -61,17 +66,12 @@ module Hbc
end
end
-module FakeSystemCommandHooks
- def after_teardown
- super
- Hbc::FakeSystemCommand.verify_expectations!
- ensure
- Hbc::FakeSystemCommand.clear
- end
-end
-
-module MiniTest
- class Spec
- include FakeSystemCommandHooks
+RSpec.configure do |config|
+ config.after(:each) do
+ begin
+ Hbc::FakeSystemCommand.verify_expectations!
+ ensure
+ Hbc::FakeSystemCommand.clear
+ end
end
end
diff --git a/Library/Homebrew/cask/spec/support/install_helper.rb b/Library/Homebrew/cask/spec/support/install_helper.rb
index c8023c66b3..d91b9ea572 100644
--- a/Library/Homebrew/cask/spec/support/install_helper.rb
+++ b/Library/Homebrew/cask/spec/support/install_helper.rb
@@ -1,10 +1,42 @@
module InstallHelper
- class << self
- def install_without_artifacts(cask)
- Hbc::Installer.new(cask).tap do |i|
+ module_function
+
+ require "test/support/helper/shutup"
+ extend Test::Helper::Shutup
+
+ def self.install_without_artifacts(cask)
+ Hbc::Installer.new(cask).tap do |i|
+ shutup do
i.download
i.extract_primary_container
end
end
end
+
+ def self.install_without_artifacts_with_caskfile(cask)
+ Hbc::Installer.new(cask).tap do |i|
+ shutup do
+ i.download
+ i.extract_primary_container
+ i.save_caskfile
+ end
+ end
+ end
+
+ def install_without_artifacts(cask)
+ Hbc::Installer.new(cask).tap do |i|
+ shutup do
+ i.download
+ i.extract_primary_container
+ end
+ end
+ end
+
+ def install_with_caskfile(cask)
+ Hbc::Installer.new(cask).tap do |i|
+ shutup do
+ i.save_caskfile
+ end
+ end
+ end
end
diff --git a/Library/Homebrew/cask/test/support/never_sudo_system_command.rb b/Library/Homebrew/cask/spec/support/never_sudo_system_command.rb
similarity index 84%
rename from Library/Homebrew/cask/test/support/never_sudo_system_command.rb
rename to Library/Homebrew/cask/spec/support/never_sudo_system_command.rb
index 8a370df447..eb8b677f27 100644
--- a/Library/Homebrew/cask/test/support/never_sudo_system_command.rb
+++ b/Library/Homebrew/cask/spec/support/never_sudo_system_command.rb
@@ -1,3 +1,5 @@
+require "hbc/system_command"
+
module Hbc
class NeverSudoSystemCommand < SystemCommand
def self.run(command, options = {})
diff --git a/Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb b/Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb
new file mode 100644
index 0000000000..400ff40f62
--- /dev/null
+++ b/Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb
@@ -0,0 +1,23 @@
+require "hbc/dsl/base"
+
+shared_examples Hbc::DSL::Base do
+ it "supports the token method" do
+ expect(dsl.token).to eq(cask.token)
+ end
+
+ it "supports the version method" do
+ expect(dsl.version).to eq(cask.version)
+ end
+
+ it "supports the caskroom_path method" do
+ expect(dsl.caskroom_path).to eq(cask.caskroom_path)
+ end
+
+ it "supports the staged_path method" do
+ expect(dsl.staged_path).to eq(cask.staged_path)
+ end
+
+ it "supports the appdir method" do
+ expect(dsl.appdir).to eq(cask.appdir)
+ end
+end
diff --git a/Library/Homebrew/cask/test/support/shared_examples/staged.rb b/Library/Homebrew/cask/spec/support/shared_examples/staged.rb
similarity index 50%
rename from Library/Homebrew/cask/test/support/shared_examples/staged.rb
rename to Library/Homebrew/cask/spec/support/shared_examples/staged.rb
index 95e75726e8..f791696aca 100644
--- a/Library/Homebrew/cask/test/support/shared_examples/staged.rb
+++ b/Library/Homebrew/cask/spec/support/shared_examples/staged.rb
@@ -1,15 +1,19 @@
-require "test_helper"
+require "spec_helper"
-shared_examples_for Hbc::Staged do
+require "hbc/staged"
+
+shared_examples Hbc::Staged do
let(:fake_pathname_exists) {
- fake_pathname = Pathname("/path/to/file/that/exists")
- fake_pathname.stubs(exist?: true, expand_path: fake_pathname)
+ fake_pathname = Pathname.new("/path/to/file/that/exists")
+ allow(fake_pathname).to receive(:exist?).and_return(true)
+ allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname)
fake_pathname
}
let(:fake_pathname_does_not_exist) {
- fake_pathname = Pathname("/path/to/file/that/does/not/exist")
- fake_pathname.stubs(exist?: false, expand_path: fake_pathname)
+ fake_pathname = Pathname.new("/path/to/file/that/does/not/exist")
+ allow(fake_pathname).to receive(:exist?).and_return(false)
+ allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname)
fake_pathname
}
@@ -17,93 +21,123 @@ shared_examples_for Hbc::Staged do
Hbc::FakeSystemCommand.expects_command(
["echo", "homebrew-cask", "rocks!"]
)
- staged.system_command("echo", args: ["homebrew-cask", "rocks!"])
+
+ shutup do
+ staged.system_command("echo", args: ["homebrew-cask", "rocks!"])
+ end
end
it "can get the Info.plist file for the primary app" do
- staged.info_plist_file.to_s.must_include Hbc.appdir.join("TestCask.app/Contents/Info.plist")
+ expect(staged.info_plist_file.to_s).to include Hbc.appdir.join("TestCask.app/Contents/Info.plist")
end
it "can execute commands on the Info.plist file" do
- staged.stubs(bundle_identifier: "com.example.BasicCask")
+ allow(staged).to receive(:bundle_identifier).and_return("com.example.BasicCask")
Hbc::FakeSystemCommand.expects_command(
["/usr/libexec/PlistBuddy", "-c", "Print CFBundleIdentifier", staged.info_plist_file]
)
- staged.plist_exec("Print CFBundleIdentifier")
+
+ shutup do
+ staged.plist_exec("Print CFBundleIdentifier")
+ end
end
it "can set a key in the Info.plist file" do
- staged.stubs(bundle_identifier: "com.example.BasicCask")
+ allow(staged).to receive(:bundle_identifier).and_return("com.example.BasicCask")
Hbc::FakeSystemCommand.expects_command(
["/usr/libexec/PlistBuddy", "-c", "Set :JVMOptions:JVMVersion 1.6+", staged.info_plist_file]
)
- staged.plist_set(":JVMOptions:JVMVersion", "1.6+")
+
+ shutup do
+ staged.plist_set(":JVMOptions:JVMVersion", "1.6+")
+ end
end
it "can set the permissions of a file" do
fake_pathname = fake_pathname_exists
- staged.stubs(Pathname: fake_pathname)
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
Hbc::FakeSystemCommand.expects_command(
["/bin/chmod", "-R", "--", "777", fake_pathname]
)
- staged.set_permissions(fake_pathname.to_s, "777")
+
+ shutup do
+ staged.set_permissions(fake_pathname.to_s, "777")
+ end
end
it "can set the permissions of multiple files" do
fake_pathname = fake_pathname_exists
- staged.stubs(:Pathname).returns(fake_pathname)
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
Hbc::FakeSystemCommand.expects_command(
["/bin/chmod", "-R", "--", "777", fake_pathname, fake_pathname]
)
- staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777")
+
+ shutup do
+ staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777")
+ end
end
it "cannot set the permissions of a file that does not exist" do
fake_pathname = fake_pathname_does_not_exist
- staged.stubs(Pathname: fake_pathname)
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
staged.set_permissions(fake_pathname.to_s, "777")
end
it "can set the ownership of a file" do
- staged.stubs(current_user: "fake_user")
fake_pathname = fake_pathname_exists
- staged.stubs(Pathname: fake_pathname)
+
+ allow(staged).to receive(:current_user).and_return("fake_user")
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
Hbc::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname]
)
- staged.set_ownership(fake_pathname.to_s)
+
+ shutup do
+ staged.set_ownership(fake_pathname.to_s)
+ end
end
it "can set the ownership of multiple files" do
- staged.stubs(current_user: "fake_user")
fake_pathname = fake_pathname_exists
- staged.stubs(Pathname: fake_pathname)
+
+ allow(staged).to receive(:current_user).and_return("fake_user")
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
Hbc::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname, fake_pathname]
)
- staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s])
+
+ shutup do
+ staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s])
+ end
end
it "can set the ownership of a file with a different user and group" do
fake_pathname = fake_pathname_exists
- staged.stubs(Pathname: fake_pathname)
+
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
Hbc::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "other_user:other_group", fake_pathname]
)
- staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group")
+
+ shutup do
+ staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group")
+ end
end
it "cannot set the ownership of a file that does not exist" do
- staged.stubs(current_user: "fake_user")
+ allow(staged).to receive(:current_user).and_return("fake_user")
fake_pathname = fake_pathname_does_not_exist
- staged.stubs(Pathname: fake_pathname)
- staged.set_ownership(fake_pathname.to_s)
+ allow(staged).to receive(:Pathname).and_return(fake_pathname)
+
+ shutup do
+ staged.set_ownership(fake_pathname.to_s)
+ end
end
end
diff --git a/Library/Homebrew/cask/test/upload_coverage.rb b/Library/Homebrew/cask/spec/upload_coverage.rb
similarity index 100%
rename from Library/Homebrew/cask/test/upload_coverage.rb
rename to Library/Homebrew/cask/spec/upload_coverage.rb
diff --git a/Library/Homebrew/cask/test/cask/accessibility_test.rb b/Library/Homebrew/cask/test/cask/accessibility_test.rb
deleted file mode 100644
index 6576294692..0000000000
--- a/Library/Homebrew/cask/test/cask/accessibility_test.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require "test_helper"
-
-# TODO: this test should be named after the corresponding class, once
-# that class is abstracted from installer.rb.
-describe "Accessibility Access" do
- let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") }
- let(:with_fake_command) { { command: Hbc::FakeSystemCommand } }
- let(:installer) { Hbc::Installer.new(cask, with_fake_command) }
-
- describe "install" do
- it "can enable accessibility access" do
- MacOS.stub :version, MacOS::Version.new("10.9") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"]
- )
- shutup do
- installer.enable_accessibility_access
- end
- end
- end
- end
-
- it "can enable accessibility access in macOS releases prior to Mavericks" do
- MacOS.stub :version, MacOS::Version.new("10.8") do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/touch", Hbc.pre_mavericks_accessibility_dotfile]
- )
- shutup do
- installer.enable_accessibility_access
- end
- end
- end
-
- it "warns about enabling accessibility access on new macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.12") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.enable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be enabled automatically on this version of macOS.")
- end
- end
- end
- end
-
- describe "uninstall" do
- it "can disable accessibility access" do
- MacOS.stub :version, MacOS::Version.new("10.9") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"]
- )
- shutup do
- installer.disable_accessibility_access
- end
- end
- end
- end
-
- it "warns about disabling accessibility access on old macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.8") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.disable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be disabled automatically on this version of macOS.")
- end
- end
- end
-
- it "warns about disabling accessibility access on new macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.12") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.disable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be disabled automatically on this version of macOS.")
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb
deleted file mode 100644
index b054290ce3..0000000000
--- a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require "test_helper"
-
-describe Hbc::Artifact::Pkg do
- before do
- @cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb")
- shutup do
- TestHelper.install_without_artifacts(@cask)
- end
- end
-
- describe "install_phase" do
- it "runs the system installer on the specified pkgs" do
- pkg = Hbc::Artifact::Pkg.new(@cask,
- command: Hbc::FakeSystemCommand)
-
- Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"])
-
- shutup do
- pkg.install_phase
- end
- end
- end
-
- describe "choices" do
- before do
- @cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb")
- shutup do
- TestHelper.install_without_artifacts(@cask)
- end
- end
-
- it "passes the choice changes xml to the system installer" do
- pkg = Hbc::Artifact::Pkg.new(@cask, command: Hbc::FakeSystemCommand)
-
- file = mock
- file.expects(:write).with <<-EOS.undent
-
-
-
-
- \t
- \t\tattributeSetting
- \t\t1
- \t\tchoiceAttribute
- \t\tselected
- \t\tchoiceIdentifier
- \t\tchoice1
- \t
-
-
- EOS
- file.stubs path: Pathname.new("/tmp/choices.xml")
- file.expects(:close)
- file.expects(:unlink)
- Tempfile.expects(:open).yields file
-
- Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/", "-applyChoiceChangesXML", @cask.staged_path.join("/tmp/choices.xml")])
-
- shutup do
- pkg.install_phase
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/cli/audit_test.rb b/Library/Homebrew/cask/test/cask/cli/audit_test.rb
deleted file mode 100644
index 89a7d140ab..0000000000
--- a/Library/Homebrew/cask/test/cask/cli/audit_test.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require "test_helper"
-
-describe Hbc::CLI::Audit do
- let(:auditor) { mock }
- let(:cask) { mock }
-
- describe "selection of Casks to audit" do
- it "audits all Casks if no tokens are given" do
- Hbc.stub :all, [cask, cask] do
- auditor.expects(:audit).times(2)
-
- run_audit([], auditor)
- end
- end
-
- it "audits specified Casks if tokens are given" do
- cask_token = "nice-app"
- Hbc.expects(:load).with(cask_token).returns(cask)
- auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
-
- run_audit([cask_token], auditor)
- end
- end
-
- describe "rules for downloading a Cask" do
- it "does not download the Cask per default" do
- Hbc.stub :load, cask do
- auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
-
- run_audit(["casktoken"], auditor)
- end
- end
-
- it "download a Cask if --download flag is set" do
- Hbc.stub :load, cask do
- auditor.expects(:audit).with(cask, audit_download: true, check_token_conflicts: false)
-
- run_audit(["casktoken", "--download"], auditor)
- end
- end
- end
-
- describe "rules for checking token conflicts" do
- it "does not check for token conflicts per default" do
- Hbc.stub :load, cask do
- auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
-
- run_audit(["casktoken"], auditor)
- end
- end
-
- it "checks for token conflicts if --token-conflicts flag is set" do
- Hbc.stub :load, cask do
- auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: true)
-
- run_audit(["casktoken", "--token-conflicts"], auditor)
- end
- end
- end
-
- def run_audit(args, auditor)
- Hbc::CLI::Audit.new(args, auditor).run
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
deleted file mode 100644
index d34a2c6bb6..0000000000
--- a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require "test_helper"
-
-describe Hbc::CLI::Reinstall do
- it "allows reinstalling a Cask" do
- shutup do
- Hbc::CLI::Install.run("local-transmission")
- end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed?
-
- shutup do
- Hbc::CLI::Reinstall.run("local-transmission")
- end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed?
- end
-
- it "allows reinstalling a non installed Cask" do
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").wont_be :installed?
-
- shutup do
- Hbc::CLI::Reinstall.run("local-transmission")
- end
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed?
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/cli/search_test.rb b/Library/Homebrew/cask/test/cask/cli/search_test.rb
deleted file mode 100644
index 6eb6badb96..0000000000
--- a/Library/Homebrew/cask/test/cask/cli/search_test.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require "test_helper"
-
-describe Hbc::CLI::Search do
- it "lists the available Casks that match the search term" do
- lambda {
- Hbc::CLI::Search.run("photoshop")
- }.must_output <<-EOS.undent
- ==> Partial matches
- adobe-photoshop-cc
- adobe-photoshop-lightroom
- EOS
- end
-
- it "shows that there are no Casks matching a search term that did not result in anything" do
- lambda {
- Hbc::CLI::Search.run("foo-bar-baz")
- }.must_output("No Cask found for \"foo-bar-baz\".\n")
- end
-
- it "lists all available Casks with no search term" do
- out = capture_io { Hbc::CLI::Search.run }[0]
- out.must_match(/google-chrome/)
- out.length.must_be :>, 1000
- end
-
- it "ignores hyphens in search terms" do
- out = capture_io { Hbc::CLI::Search.run("goo-gle-chrome") }[0]
- out.must_match(/google-chrome/)
- out.length.must_be :<, 100
- end
-
- it "ignores hyphens in Cask tokens" do
- out = capture_io { Hbc::CLI::Search.run("googlechrome") }[0]
- out.must_match(/google-chrome/)
- out.length.must_be :<, 100
- end
-
- it "accepts multiple arguments" do
- out = capture_io { Hbc::CLI::Search.run("google chrome") }[0]
- out.must_match(/google-chrome/)
- out.length.must_be :<, 100
- end
-
- it "accepts a regexp argument" do
- lambda {
- Hbc::CLI::Search.run("/^google-c[a-z]rome$/")
- }.must_output "==> Regexp matches\ngoogle-chrome\n"
- end
-
- it "Returns both exact and partial matches" do
- out = capture_io { Hbc::CLI::Search.run("mnemosyne") }[0]
- out.must_match(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/)
- end
-
- it "does not search the Tap name" do
- out = capture_io { Hbc::CLI::Search.run("caskroom") }[0]
- out.must_match(/^No Cask found for "caskroom"\.\n/)
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/cli/version_test.rb b/Library/Homebrew/cask/test/cask/cli/version_test.rb
deleted file mode 100644
index 60e6d22aec..0000000000
--- a/Library/Homebrew/cask/test/cask/cli/version_test.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require "test_helper"
-
-describe "brew cask --version" do
- it "respects the --version argument" do
- lambda {
- Hbc::CLI::NullCommand.new("--version").run
- }.must_output Hbc.full_version
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/depends_on_test.rb b/Library/Homebrew/cask/test/cask/depends_on_test.rb
deleted file mode 100644
index 1ec85b520b..0000000000
--- a/Library/Homebrew/cask/test/cask/depends_on_test.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-require "test_helper"
-
-# TODO: this test should be named after the corresponding class, once
-# that class is abstracted from installer.rb
-describe "Satisfy Dependencies and Requirements" do
- # TODO: test that depends_on formula invokes Homebrew
- #
- # describe "depends_on formula" do
- # it "" do
- # end
- # end
- #
-
- describe "depends_on cask" do
- it "raises an exception when depends_on cask is cyclic" do
- dep_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb")
- lambda {
- shutup do
- Hbc::Installer.new(dep_cask).install
- end
- }.must_raise(Hbc::CaskCyclicCaskDependencyError)
- end
-
- it "installs the dependency of a Cask and the Cask itself" do
- csk = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb")
- dependency = Hbc.load(csk.depends_on.cask.first)
- shutup do
- Hbc::Installer.new(csk).install
- end
-
- csk.must_be :installed?
- dependency.must_be :installed?
- end
- end
-
- describe "depends_on macos" do
- it "understands depends_on macos: " do
- macos_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-array.rb")
- shutup do
- Hbc::Installer.new(macos_cask).install
- end
- end
-
- it "understands depends_on macos: " do
- macos_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb")
- shutup do
- Hbc::Installer.new(macos_cask).install
- end
- end
-
- it "understands depends_on macos: " do
- macos_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-string.rb")
- shutup do
- Hbc::Installer.new(macos_cask).install
- end
- end
-
- it "understands depends_on macos: " do
- macos_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-symbol.rb")
- shutup do
- Hbc::Installer.new(macos_cask).install
- end
- end
-
- it "raises an exception when depends_on macos is not satisfied" do
- macos_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-failure.rb")
- lambda {
- shutup do
- Hbc::Installer.new(macos_cask).install
- end
- }.must_raise(Hbc::CaskError)
- end
- end
-
- describe "depends_on arch" do
- it "succeeds when depends_on arch is satisfied" do
- arch_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-arch.rb")
- shutup do
- Hbc::Installer.new(arch_cask).install
- end
- end
- end
-
- describe "depends_on x11" do
- it "succeeds when depends_on x11 is satisfied" do
- x11_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb")
- MacOS::X11.stubs(:installed?).returns(true)
- shutup do
- Hbc::Installer.new(x11_cask).install
- end
- end
-
- it "raises an exception when depends_on x11 is not satisfied" do
- x11_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb")
- MacOS::X11.stubs(:installed?).returns(false)
- lambda {
- shutup do
- Hbc::Installer.new(x11_cask).install
- end
- }.must_raise(Hbc::CaskX11DependencyError)
- end
-
- it "never raises when depends_on x11: false" do
- x11_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11-false.rb")
- MacOS::X11.stubs(:installed?).returns(false)
- lambda do
- shutup do
- Hbc::Installer.new(x11_cask).install
- end
- end # won't raise
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/dsl_test.rb b/Library/Homebrew/cask/test/cask/dsl_test.rb
deleted file mode 100644
index cdd06a8364..0000000000
--- a/Library/Homebrew/cask/test/cask/dsl_test.rb
+++ /dev/null
@@ -1,479 +0,0 @@
-require "test_helper"
-
-describe Hbc::DSL do
- it "lets you set url, homepage, and version" do
- test_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb")
- 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
-
- describe "when a Cask includes an unknown method" do
- attempt_unknown_method = nil
-
- before do
- attempt_unknown_method = lambda do
- Hbc::Cask.new("unexpected-method-cask") do
- future_feature :not_yet_on_your_machine
- end
- end
- end
-
- it "prints a warning that it has encountered an unexpected method" do
- expected = Regexp.compile(<<-EOS.undent.lines.map(&:chomp).join(""))
- (?m)
- Warning:
- .*
- Unexpected method 'future_feature' called on Cask unexpected-method-cask\\.
- .*
- https://github.com/caskroom/homebrew-cask/blob/master/doc/reporting_bugs/pre_bug_report.md
- .*
- https://github.com/caskroom/homebrew-cask#reporting-bugs
- EOS
-
- attempt_unknown_method.must_output nil, expected
- end
-
- it "will simply warn, not throw an exception" do
- begin
- shutup do
- attempt_unknown_method.call
- end
- rescue StandardError => e
- flunk("Wanted unexpected method to simply warn, but got exception #{e}")
- end
- end
- end
-
- describe "header line" do
- it "requires a valid header format" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-header-format.rb")
- }.must_raise(SyntaxError)
- end
-
- it "requires the header token to match the file name" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-header-token-mismatch.rb")
- }.must_raise(Hbc::CaskTokenDoesNotMatchError)
- err.message.must_include "Bad header line:"
- err.message.must_include "does not match file name"
- end
-
- it "does not require a DSL version in the header" do
- test_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-dsl-version.rb")
- test_cask.token.must_equal "no-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
-
- it "may use deprecated DSL version hash syntax" do
- stub = proc do |arg|
- arg == "HOMEBREW_DEVELOPER" ? nil : ENV[arg]
- end
-
- ENV.stub :[], stub do
- shutup do
- test_cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-dsl-version.rb")
- 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
-
- describe "name stanza" do
- it "lets you set the full name via a name stanza" do
- cask = Hbc::Cask.new("name-cask") do
- name "Proper Name"
- end
-
- cask.name.must_equal [
- "Proper Name",
- ]
- end
-
- it "Accepts an array value to the name stanza" do
- cask = Hbc::Cask.new("array-name-cask") do
- name ["Proper Name", "Alternate Name"]
- end
-
- cask.name.must_equal [
- "Proper Name",
- "Alternate Name",
- ]
- end
-
- it "Accepts multiple name stanzas" do
- cask = Hbc::Cask.new("multi-name-cask") do
- name "Proper Name"
- name "Alternate Name"
- end
-
- cask.name.must_equal [
- "Proper Name",
- "Alternate Name",
- ]
- end
- end
-
- describe "sha256 stanza" do
- it "lets you set checksum via sha256" do
- cask = Hbc::Cask.new("checksum-cask") do
- sha256 "imasha2"
- end
-
- cask.sha256.must_equal "imasha2"
- end
- end
-
- describe "language stanza" do
- it "allows multilingual casks" do
- cask = lambda do
- Hbc::Cask.new("cask-with-apps") do
- language "zh" do
- sha256 "abc123"
- "zh-CN"
- end
-
- language "en-US", default: true do
- sha256 "xyz789"
- "en-US"
- end
-
- url "https://example.org/#{language}.zip"
- end
- end
-
- MacOS.stub :languages, ["zh"] do
- cask.call.language.must_equal "zh-CN"
- cask.call.sha256.must_equal "abc123"
- cask.call.url.to_s.must_equal "https://example.org/zh-CN.zip"
- end
-
- MacOS.stub :languages, ["zh-XX"] do
- cask.call.language.must_equal "zh-CN"
- cask.call.sha256.must_equal "abc123"
- cask.call.url.to_s.must_equal "https://example.org/zh-CN.zip"
- end
-
- MacOS.stub :languages, ["en"] do
- cask.call.language.must_equal "en-US"
- cask.call.sha256.must_equal "xyz789"
- cask.call.url.to_s.must_equal "https://example.org/en-US.zip"
- end
-
- MacOS.stub :languages, ["xx-XX"] do
- cask.call.language.must_equal "en-US"
- cask.call.sha256.must_equal "xyz789"
- cask.call.url.to_s.must_equal "https://example.org/en-US.zip"
- end
-
- MacOS.stub :languages, ["xx-XX", "zh", "en"] do
- cask.call.language.must_equal "zh-CN"
- cask.call.sha256.must_equal "abc123"
- cask.call.url.to_s.must_equal "https://example.org/zh-CN.zip"
- end
-
- MacOS.stub :languages, ["xx-XX", "en-US", "zh"] do
- cask.call.language.must_equal "en-US"
- cask.call.sha256.must_equal "xyz789"
- cask.call.url.to_s.must_equal "https://example.org/en-US.zip"
- end
- end
- end
-
- describe "app stanza" do
- it "allows you to specify app stanzas" do
- cask = Hbc::Cask.new("cask-with-apps") do
- app "Foo.app"
- app "Bar.app"
- end
-
- Array(cask.artifacts[:app]).must_equal [["Foo.app"], ["Bar.app"]]
- end
-
- it "allow app stanzas to be empty" do
- cask = Hbc::Cask.new("cask-with-no-apps")
- Array(cask.artifacts[:app]).must_equal %w[]
- end
- end
-
- describe "caveats stanza" do
- it "allows caveats to be specified via a method define" do
- cask = Hbc::Cask.new("plain-cask")
-
- cask.caveats.must_be :empty?
-
- cask = Hbc::Cask.new("cask-with-caveats") do
- def caveats; <<-EOS.undent
- When you install this Cask, you probably want to know this.
- EOS
- end
- end
-
- cask.caveats.must_equal "When you install this Cask, you probably want to know this.\n"
- end
- end
-
- describe "pkg stanza" do
- it "allows installable pkgs to be specified" do
- cask = Hbc::Cask.new("cask-with-pkgs") do
- pkg "Foo.pkg"
- pkg "Bar.pkg"
- end
-
- Array(cask.artifacts[:pkg]).must_equal [["Foo.pkg"], ["Bar.pkg"]]
- end
- end
-
- describe "url stanza" do
- it "prevents defining multiple urls" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-two-url.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'url' stanza may only appear once"
- end
- end
-
- describe "homepage stanza" do
- it "prevents defining multiple homepages" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-two-homepage.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'homepage' stanza may only appear once"
- end
- end
-
- describe "version stanza" do
- it "prevents defining multiple versions" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-two-version.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'version' stanza may only appear once"
- end
- end
-
- describe "appcast stanza" do
- it "allows appcasts to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-appcast.rb")
- cask.appcast.to_s.must_match(/^http/)
- end
-
- it "prevents defining multiple appcasts" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-appcast-multiple.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'appcast' stanza may only appear once"
- end
-
- it "refuses to load invalid appcast URLs" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-appcast-url.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "gpg stanza" do
- it "allows gpg stanza to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-gpg.rb")
- cask.gpg.to_s.must_match(/\S/)
- end
-
- it "allows gpg stanza to be specified with :key_url" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-gpg-key-url.rb")
- cask.gpg.to_s.must_match(/\S/)
- end
-
- it "prevents specifying gpg stanza multiple times" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-multiple-stanzas.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'gpg' stanza may only appear once"
- end
-
- it "prevents missing gpg key parameters" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-missing-key.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'gpg' stanza must include exactly one"
- end
-
- it "prevents conflicting gpg key parameters" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-conflicting-keys.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'gpg' stanza must include exactly one"
- end
-
- it "refuses to load invalid gpg signature URLs" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-signature-url.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
-
- it "refuses to load invalid gpg key URLs" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-key-url.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
-
- it "refuses to load invalid gpg key IDs" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-key-id.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
-
- it "refuses to load if gpg parameter is unknown" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-gpg-parameter.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "depends_on stanza" do
- it "refuses to load with an invalid depends_on key" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-depends-on-key.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "depends_on formula" do
- it "allows depends_on formula to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-formula.rb")
- cask.depends_on.formula.wont_be_nil
- end
-
- it "allows multiple depends_on formula to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-formula-multiple.rb")
- cask.depends_on.formula.wont_be_nil
- end
- end
-
- describe "depends_on cask" do
- it "allows depends_on cask to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb")
- cask.depends_on.cask.wont_be_nil
- end
-
- it "allows multiple depends_on cask to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")
- cask.depends_on.cask.wont_be_nil
- end
- end
-
- describe "depends_on macos" do
- it "allows depends_on macos to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-string.rb")
- cask.depends_on.macos.wont_be_nil
- end
- it "refuses to load with an invalid depends_on macos value" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-depends-on-macos-bad-release.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- it "refuses to load with conflicting depends_on macos forms" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "depends_on arch" do
- it "allows depends_on arch to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-arch.rb")
- cask.depends_on.arch.wont_be_nil
- end
- it "refuses to load with an invalid depends_on arch value" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-depends-on-arch-value.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "depends_on x11" do
- it "allows depends_on x11 to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb")
- cask.depends_on.x11.wont_be_nil
- end
- it "refuses to load with an invalid depends_on x11 value" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-depends-on-x11-value.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "conflicts_with stanza" do
- it "allows conflicts_with stanza to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb")
- cask.conflicts_with.formula.wont_be_nil
- end
-
- it "refuses to load invalid conflicts_with key" do
- lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-conflicts-with-key.rb")
- }.must_raise(Hbc::CaskInvalidError)
- end
- end
-
- describe "installer stanza" do
- it "allows installer script to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installer-script.rb")
- cask.artifacts[:installer].first.script[:executable].must_equal "/usr/bin/true"
- cask.artifacts[:installer].first.script[:args].must_equal ["--flag"]
- cask.artifacts[:installer].to_a[1].script[:executable].must_equal "/usr/bin/false"
- cask.artifacts[:installer].to_a[1].script[:args].must_equal ["--flag"]
- end
- it "allows installer manual to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installer-manual.rb")
- cask.artifacts[:installer].first.manual.must_equal "Caffeine.app"
- end
- end
-
- describe "stage_only stanza" do
- it "allows stage_only stanza to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/stage-only.rb")
- cask.artifacts[:stage_only].first.must_equal [true]
- end
-
- it "prevents specifying stage_only with other activatables" do
- err = lambda {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/invalid/invalid-stage-only-conflict.rb")
- }.must_raise(Hbc::CaskInvalidError)
- err.message.must_include "'stage_only' must be the only activatable artifact"
- end
- end
-
- describe "auto_updates stanza" do
- it "allows auto_updates stanza to be specified" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb")
- cask.auto_updates.must_equal true
- end
- end
-
- describe "appdir" do
- it "allows interpolation of the appdir value in stanzas" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/appdir-interpolation.rb")
- cask.artifacts[:binary].first.must_equal ["#{Hbc.appdir}/some/path"]
- end
-
- it "does not include a trailing slash" do
- original_appdir = Hbc.appdir
- Hbc.appdir = "#{original_appdir}/"
-
- begin
- cask = Hbc::Cask.new("appdir-trailing-slash") do
- binary "#{appdir}/some/path"
- end
-
- cask.artifacts[:binary].first.must_equal ["#{original_appdir}/some/path"]
- ensure
- Hbc.appdir = original_appdir
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/pkg_test.rb b/Library/Homebrew/cask/test/cask/pkg_test.rb
deleted file mode 100644
index ac43f9e633..0000000000
--- a/Library/Homebrew/cask/test/cask/pkg_test.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require "test_helper"
-
-describe Hbc::Pkg do
- describe "uninstall" do
- it "removes files and dirs referenced by the pkg" do
- pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand)
-
- some_files = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) }
- pkg.stubs(:pkgutil_bom_files).returns some_files
-
- some_specials = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) }
- pkg.stubs(:pkgutil_bom_specials).returns some_specials
-
- some_dirs = Array.new(3) { Pathname.new(Dir.mktmpdir) }
- pkg.stubs(:pkgutil_bom_dirs).returns some_dirs
-
- pkg.stubs(:forget)
-
- pkg.uninstall
-
- some_files.each do |file|
- file.wont_be :exist?
- end
-
- some_dirs.each do |dir|
- dir.wont_be :exist?
- end
- end
-
- it "forgets the pkg" do
- pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::FakeSystemCommand)
-
- Hbc::FakeSystemCommand.stubs_command(
- ["/usr/sbin/pkgutil", "--only-files", "--files", "my.fake.pkg"]
- )
- Hbc::FakeSystemCommand.stubs_command(
- ["/usr/sbin/pkgutil", "--only-dirs", "--files", "my.fake.pkg"]
- )
- Hbc::FakeSystemCommand.stubs_command(
- ["/usr/sbin/pkgutil", "--files", "my.fake.pkg"]
- )
-
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/sbin/pkgutil", "--forget", "my.fake.pkg"]
- )
-
- pkg.uninstall
- end
-
- it "cleans broken symlinks, but leaves AOK symlinks" do
- pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand)
-
- fake_dir = Pathname.new(Dir.mktmpdir)
- fake_file = fake_dir.join("ima_file").tap { |path| FileUtils.touch(path) }
-
- intact_symlink = fake_dir.join("intact_symlink").tap { |path| path.make_symlink(fake_file) }
- broken_symlink = fake_dir.join("broken_symlink").tap { |path| path.make_symlink("im_nota_file") }
-
- pkg.stubs(:pkgutil_bom_specials).returns([])
- pkg.stubs(:pkgutil_bom_files).returns([])
- pkg.stubs(:pkgutil_bom_dirs).returns([fake_dir])
- pkg.stubs(:forget)
-
- pkg.uninstall
-
- intact_symlink.must_be :exist?
- broken_symlink.wont_be :exist?
- fake_dir.must_be :exist?
- end
-
- it "cleans files incorrectly reported as directories" do
- pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand)
-
- fake_dir = Pathname.new(Dir.mktmpdir)
- fake_file = fake_dir.join("ima_file_pretending_to_be_a_dir").tap { |path| FileUtils.touch(path) }
-
- pkg.stubs(:pkgutil_bom_specials).returns([])
- pkg.stubs(:pkgutil_bom_files).returns([])
- pkg.stubs(:pkgutil_bom_dirs).returns([fake_file, fake_dir])
- pkg.stubs(:forget)
-
- pkg.uninstall
-
- fake_file.wont_be :exist?
- fake_dir.wont_be :exist?
- end
-
- it "snags permissions on ornery dirs, but returns them afterwords" do
- pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand)
-
- fake_dir = Pathname.new(Dir.mktmpdir)
-
- fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) }
-
- fake_dir.chmod(0000)
-
- pkg.stubs(:pkgutil_bom_specials).returns([])
- pkg.stubs(:pkgutil_bom_files).returns([fake_file])
- pkg.stubs(:pkgutil_bom_dirs).returns([fake_dir])
- pkg.stubs(:forget)
-
- shutup do
- pkg.uninstall
- end
-
- fake_dir.must_be :directory?
- fake_file.wont_be :file?
- (fake_dir.stat.mode % 01000).to_s(8).must_equal "0"
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask/url_checker_test.rb b/Library/Homebrew/cask/test/cask/url_checker_test.rb
deleted file mode 100644
index afd4532ddd..0000000000
--- a/Library/Homebrew/cask/test/cask/url_checker_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require "test_helper"
-
-describe Hbc::UrlChecker do
- describe "request processing" do
- let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
- let(:checker) { Hbc::UrlChecker.new(cask) }
- let(:with_stubbed_fetcher) {
- lambda { |&block|
- Hbc::Fetcher.stub(:head, response) do
- checker.run
- instance_eval(&block)
- end
- }
- }
-
- describe "with an empty response" do
- let(:response) { "" }
-
- it "adds an error" do
- with_stubbed_fetcher.call do
- expect(checker.errors).must_include("timeout while requesting #{cask.url}")
- end
- end
- end
-
- describe "with a valid http response" do
- let(:response) {
- <<-EOS.undent
- HTTP/1.1 200 OK
- Content-Type: application/x-apple-diskimage
- ETag: "b4208f3e84967be4b078ecaa03fba941"
- Content-Length: 23726161
- Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT
- EOS
- }
-
- it "properly populates the response code and headers" do
- with_stubbed_fetcher.call do
- expect(checker.errors).must_be_empty
- expect(checker.response_status).must_equal("HTTP/1.1 200 OK")
- expect(checker.headers).must_equal(
- "Content-Type" => "application/x-apple-diskimage",
- "ETag" => '"b4208f3e84967be4b078ecaa03fba941"',
- "Content-Length" => "23726161",
- "Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT"
- )
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/cask_test.rb b/Library/Homebrew/cask/test/cask_test.rb
deleted file mode 100644
index d3abda2745..0000000000
--- a/Library/Homebrew/cask/test/cask_test.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require "test_helper"
-
-describe "Cask" do
- hbc_relative_tap_path = "../../Taps/caskroom/homebrew-cask"
- describe "load" do
- it "returns an instance of the Cask for the given token" do
- c = Hbc.load("adium")
- c.must_be_kind_of(Hbc::Cask)
- c.token.must_equal("adium")
- end
-
- it "returns an instance of the Cask from a specific file location" do
- location = File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb")
- c = Hbc.load(location)
- c.must_be_kind_of(Hbc::Cask)
- c.token.must_equal("dia")
- end
-
- it "returns an instance of the Cask from a url" do
- url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb")
- c = shutup do
- Hbc.load(url)
- end
- c.must_be_kind_of(Hbc::Cask)
- c.token.must_equal("dia")
- end
-
- it "raises an error when failing to download a Cask from a url" do
- lambda {
- url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/notacask.rb")
- shutup do
- Hbc.load(url)
- end
- }.must_raise(Hbc::CaskUnavailableError)
- end
-
- it "returns an instance of the Cask from a relative file location" do
- c = Hbc.load(hbc_relative_tap_path + "/Casks/bbedit.rb")
- c.must_be_kind_of(Hbc::Cask)
- c.token.must_equal("bbedit")
- end
-
- it "uses exact match when loading by token" do
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/test-opera.rb").token.must_equal("test-opera")
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/test-opera-mail.rb").token.must_equal("test-opera-mail")
- end
-
- it "raises an error when attempting to load a Cask that doesn't exist" do
- lambda {
- Hbc.load("notacask")
- }.must_raise(Hbc::CaskUnavailableError)
- end
- end
-
- describe "all_tokens" do
- it "returns a token for every Cask" do
- all_cask_tokens = Hbc.all_tokens
- all_cask_tokens.count.must_be :>, 20
- all_cask_tokens.each { |token| token.must_be_kind_of String }
- end
- end
-
- describe "metadata" do
- it "proposes a versioned metadata directory name for each instance" do
- cask_token = "adium"
- c = Hbc.load(cask_token)
- metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
- c.metadata_versioned_container_path.to_s.must_equal(metadata_path.to_s)
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/plist/parser_test.rb b/Library/Homebrew/cask/test/plist/parser_test.rb
deleted file mode 100644
index 7f844e377f..0000000000
--- a/Library/Homebrew/cask/test/plist/parser_test.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require "test_helper"
-
-describe Plist do
- it "parses some hdiutil output okay" do
- hdiutil_output = <<-EOS.undent
-
-
-
-
- system-entities
-
-
- content-hint
- Apple_partition_map
- dev-entry
- /dev/disk3s1
- potentially-mountable
-
- unmapped-content-hint
- Apple_partition_map
-
-
- content-hint
- Apple_partition_scheme
- dev-entry
- /dev/disk3
- potentially-mountable
-
- unmapped-content-hint
- Apple_partition_scheme
-
-
- content-hint
- Apple_HFS
- dev-entry
- /dev/disk3s2
- mount-point
- /private/tmp/dmg.BhfS2g
- potentially-mountable
-
- unmapped-content-hint
- Apple_HFS
- volume-kind
- hfs
-
-
-
-
- EOS
-
- parsed = Plist.parse_xml(hdiutil_output)
-
- parsed.keys.must_equal ["system-entities"]
- parsed["system-entities"].length.must_equal 3
- parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[
- /dev/disk3s1
- /dev/disk3
- /dev/disk3s2
- ]
- end
-
- it "does not choke on empty input" do
- Plist.parse_xml("").must_equal {}
- end
-end
diff --git a/Library/Homebrew/cask/test/support/cleanup.rb b/Library/Homebrew/cask/test/support/cleanup.rb
deleted file mode 100644
index c31a74be22..0000000000
--- a/Library/Homebrew/cask/test/support/cleanup.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module MiniTest
- class Spec
- def after_teardown
- super
- Hbc.installed.each do |cask|
- Hbc::Installer.new(cask).purge_versioned_files
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/support/fake_dirs.rb b/Library/Homebrew/cask/test/support/fake_dirs.rb
deleted file mode 100644
index ea7acc6856..0000000000
--- a/Library/Homebrew/cask/test/support/fake_dirs.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# wire in a set of fake link dirs per-test
-module FakeDirHooks
- DIRS = [:appdir, :qlplugindir, :binarydir].freeze
-
- def before_setup
- super
-
- @canned_dirs = {}
-
- DIRS.each do |dir_name|
- dir = HOMEBREW_PREFIX.join("#{dir_name}-#{Time.now.to_i}-#{rand(1024)}")
- dir.mkpath
- Hbc.send("#{dir_name}=", dir)
- @canned_dirs[:dir_name] = dir
- end
- end
-
- def after_teardown
- super
-
- @canned_dirs.each_value do |dir|
- dir.rmtree if dir.exist?
- end
- end
-end
-
-module MiniTest
- class Spec
- include FakeDirHooks
- end
-end
diff --git a/Library/Homebrew/cask/test/support/shared_examples.rb b/Library/Homebrew/cask/test/support/shared_examples.rb
deleted file mode 100644
index 594ca81c17..0000000000
--- a/Library/Homebrew/cask/test/support/shared_examples.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# Adapted from https://gist.github.com/jodosha/1560208
-MiniTest::Spec.class_eval do
- def self.shared_examples
- @shared_examples ||= {}
- end
-end
-
-module MiniTest
- class Spec
- module SharedExamples
- def shared_examples_for(desc, &block)
- MiniTest::Spec.shared_examples[desc] = block
- end
-
- def it_behaves_like(desc, *args, &block)
- instance_exec(*args, &MiniTest::Spec.shared_examples[desc])
- instance_eval(&block) if block_given?
- end
- end
- end
-end
-
-Object.class_eval do
- include(MiniTest::Spec::SharedExamples)
-end
diff --git a/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb b/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb
deleted file mode 100644
index 28115bb4b5..0000000000
--- a/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "test_helper"
-
-shared_examples_for Hbc::DSL::Base do
- it "supports the token method" do
- dsl.token.must_equal cask.token
- end
-
- it "supports the version method" do
- dsl.version.must_equal cask.version
- end
-
- it "supports the caskroom_path method" do
- dsl.caskroom_path.must_equal cask.caskroom_path
- end
-
- it "supports the staged_path method" do
- dsl.staged_path.must_equal cask.staged_path
- end
-
- it "supports the appdir method" do
- dsl.appdir.must_equal cask.appdir
- end
-end
diff --git a/Library/Homebrew/cask/test/syntax_test.rb b/Library/Homebrew/cask/test/syntax_test.rb
deleted file mode 100644
index 0ea832bde6..0000000000
--- a/Library/Homebrew/cask/test/syntax_test.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "test_helper"
-
-describe "Syntax check" do
- project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))
- backend_files = Dir[project_root.join("**", "*.rb")].reject { |f| f.match %r{/vendor/|/Casks/} }
- interpreter = RUBY_PATH
- flags = %w[-c]
- flags.unshift "--disable-all"
- backend_files.each do |file|
- it "#{file} is valid Ruby" do
- args = flags + ["--", file]
- shutup do
- raise SyntaxError, "#{file} failed syntax check" unless system(interpreter, *args)
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb
deleted file mode 100644
index f600a1c5c8..0000000000
--- a/Library/Homebrew/cask/test/test_helper.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-require "bundler"
-require "bundler/setup"
-require "pathname"
-
-require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
-
-# add Homebrew to load path
-$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
-$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/support/lib"))
-
-require "global"
-
-# add Homebrew-Cask to load path
-$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
-
-require "test/support/helper/shutup"
-include Test::Helper::Shutup
-
-def sudo(*args)
- %w[/usr/bin/sudo -E --] + args.flatten
-end
-
-# must be called after testing_env so at_exit hooks are in proper order
-require "minitest/autorun"
-require "minitest/reporters"
-Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
-
-require "parallel_tests/test/runtime_logger"
-
-# Force mocha to patch MiniTest since we have both loaded thanks to homebrew's testing_env
-require "mocha/api"
-require "mocha/integration/mini_test"
-Mocha::Integration::MiniTest.activate
-
-# our baby
-require "hbc"
-
-# create and override default directories
-Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
-Hbc.cache.mkpath
-Hbc.caskroom = Hbc.default_caskroom.tap(&:mkpath)
-Hbc.default_tap = Tap.fetch("caskroom", "test").tap do |tap|
- # link test casks
- FileUtils.mkdir_p tap.path.dirname
- FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
-end
-
-# pretend that the caskroom/cask Tap is installed
-FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path
-
-class TestHelper
- # helpers for test Casks to reference local files easily
- def self.local_binary_path(name)
- File.expand_path(File.join(File.dirname(__FILE__), "support", "binaries", name))
- end
-
- def self.local_binary_url(name)
- "file://" + local_binary_path(name)
- end
-
- def self.valid_symlink?(candidate)
- return false unless candidate.symlink?
- candidate.readlink.exist?
- end
-
- def self.install_without_artifacts(cask)
- Hbc::Installer.new(cask).tap do |i|
- shutup do
- i.download
- i.extract_primary_container
- end
- end
- end
-
- def self.install_with_caskfile(cask)
- Hbc::Installer.new(cask).tap do |i|
- shutup do
- i.save_caskfile
- end
- end
- end
-
- def self.install_without_artifacts_with_caskfile(cask)
- Hbc::Installer.new(cask).tap do |i|
- shutup do
- i.download
- i.extract_primary_container
- i.save_caskfile
- end
- end
- end
-end
-
-# Extend MiniTest API with support for RSpec-style shared examples
-require "support/shared_examples"
-require "support/shared_examples/dsl_base.rb"
-require "support/shared_examples/staged.rb"
-
-require "support/fake_dirs"
-require "support/fake_system_command"
-require "support/cleanup"
-require "support/never_sudo_system_command"
-require "tmpdir"
-require "tempfile"