Skip to content
Snippets Groups Projects
Commit 5a90d6e8 authored by Markus Reiter's avatar Markus Reiter Committed by GitHub
Browse files

Merge pull request #1978 from reitermarkus/convert-to-spec

Convert all Cask tests to RSpec.
parents 943959b4 31b9dc28
No related branches found
No related tags found
No related merge requests found
Showing
with 527 additions and 276 deletions
......@@ -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
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?
end
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 minitest
run_tests "parallel_test", Dir["test/**/*_test.rb"]
failed ||= !$CHILD_STATUS.success?
unless $CHILD_STATUS.success?
Homebrew.failed = true
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
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
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
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
......
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
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
require "test_helper"
require "spec_helper"
describe Hbc::Artifact::Pkg do
before do
@cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb")
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
TestHelper.install_without_artifacts(@cask)
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: Hbc::FakeSystemCommand)
pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command)
Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"])
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
......@@ -22,18 +28,14 @@ describe Hbc::Artifact::Pkg do
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
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: Hbc::FakeSystemCommand)
pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command)
file = double(path: Pathname.new("/tmp/choices.xml"))
file = mock
file.expects(:write).with <<-EOS.undent
expect(file).to receive(:write).with(<<-EOS.undent)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
......@@ -49,12 +51,17 @@ describe Hbc::Artifact::Pkg do
</array>
</plist>
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")])
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
......
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
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
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
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
err.message.must_equal("It seems there is already an App at '#{target_path_mini}'.")
}.to raise_error(Hbc::CaskError, "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
err.message.must_equal("It seems there is already an App at '#{target_path_pro}'.")
}.to raise_error(Hbc::CaskError, "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
......
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.
......
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
......
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
......
......@@ -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
require "test_helper"
require "spec_helper"
describe Hbc::CLI::Audit do
let(:auditor) { mock }
let(:cask) { mock }
let(:auditor) { double }
let(:cask) { double }
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)
allow(Hbc).to receive(:all).and_return([cask, cask])
run_audit([], auditor)
end
expect(auditor).to receive(:audit).twice
run_audit([], auditor)
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)
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
......@@ -24,37 +25,33 @@ describe Hbc::CLI::Audit do
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)
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
run_audit(["casktoken"], auditor)
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)
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
run_audit(["casktoken", "--download"], auditor)
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)
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
run_audit(["casktoken"], auditor)
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)
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
run_audit(["casktoken", "--token-conflicts"], auditor)
end
end
......
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
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
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment