Merge pull request #2256 from reitermarkus/spec-cask

Make Cask tests work without tapping `caskroom/cask`.
This commit is contained in:
Markus Reiter 2017-03-05 00:31:26 +01:00 committed by GitHub
commit f84ad9ca2e
6 changed files with 38 additions and 44 deletions

View File

@ -15,6 +15,8 @@ module Hbc
@default_caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end
attr_writer :caskroom
def caskroom
@caskroom ||= begin
if Utils.path_occupied?(legacy_caskroom)
@ -36,14 +38,12 @@ module Hbc
end
end
def caskroom=(caskroom)
@caskroom = caskroom
end
def legacy_cache
@legacy_cache ||= HOMEBREW_CACHE.join("Casks")
end
attr_writer :cache
def cache
@cache ||= HOMEBREW_CACHE.join("Cask")
end

View File

@ -22,33 +22,33 @@ describe Hbc::Cask do
end
describe "load" do
let(:hbc_relative_tap_path) { "../../Taps/caskroom/homebrew-cask" }
let(:tap_path) { Hbc.default_tap.path }
let(:file_dirname) { Pathname.new(__FILE__).dirname }
let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) }
it "returns an instance of the Cask for the given token" do
c = Hbc.load("adium")
c = Hbc.load("local-caffeine")
expect(c).to be_kind_of(Hbc::Cask)
expect(c.token).to eq("adium")
expect(c.token).to eq("local-caffeine")
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 = Hbc.load("#{tap_path}/Casks/local-caffeine.rb")
expect(c).to be_kind_of(Hbc::Cask)
expect(c.token).to eq("dia")
expect(c.token).to eq("local-caffeine")
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)
Hbc.load("file://#{tap_path}/Casks/local-caffeine.rb")
end
expect(c).to be_kind_of(Hbc::Cask)
expect(c.token).to eq("dia")
expect(c.token).to eq("local-caffeine")
end
it "raises an error when failing to download a Cask from a url" do
expect {
url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/notacask.rb")
url = "file://#{tap_path}/Casks/notacask.rb"
shutup do
Hbc.load(url)
end
@ -56,9 +56,9 @@ describe Hbc::Cask do
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 = Hbc.load(relative_tap_path/"Casks/local-caffeine.rb")
expect(c).to be_kind_of(Hbc::Cask)
expect(c.token).to eq("bbedit")
expect(c.token).to eq("local-caffeine")
end
it "uses exact match when loading by token" do
@ -83,7 +83,7 @@ describe Hbc::Cask do
describe "metadata" do
it "proposes a versioned metadata directory name for each instance" do
cask_token = "adium"
cask_token = "local-caffeine"
c = Hbc.load(cask_token)
metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s)

View File

@ -64,21 +64,21 @@ describe Hbc::CLI::Install do
it "returns a suggestion for a misspelled Cask" do
expect {
begin
Hbc::CLI::Install.run("googlechrome")
Hbc::CLI::Install.run("localcaffeine")
rescue Hbc::CaskError
nil
end
}.to output(/No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/).to_stderr
}.to output(/No available Cask for localcaffeine\. Did you mean:\nlocal-caffeine/).to_stderr
end
it "returns multiple suggestions for a Cask fragment" do
expect {
begin
Hbc::CLI::Install.run("google")
Hbc::CLI::Install.run("local-caf")
rescue Hbc::CaskError
nil
end
}.to output(/No available Cask for google\. Did you mean one of:\ngoogle/).to_stderr
}.to output(/No available Cask for local-caf\. Did you mean one of:\nlocal-caffeine/).to_stderr
end
describe "when no Cask is specified" do

View File

@ -3,11 +3,11 @@ 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")
Hbc::CLI::Search.run("local")
}.to output(<<-EOS.undent).to_stdout
==> Partial matches
adobe-photoshop-cc
adobe-photoshop-lightroom
local-caffeine
local-transmission
EOS
end
@ -20,37 +20,37 @@ describe Hbc::CLI::Search do
it "lists all available Casks with no search term" do
expect {
Hbc::CLI::Search.run
}.to output(/google-chrome/).to_stdout
}.to output(/local-caffeine/).to_stdout
end
it "ignores hyphens in search terms" do
expect {
Hbc::CLI::Search.run("goo-gle-chrome")
}.to output(/google-chrome/).to_stdout
Hbc::CLI::Search.run("lo-cal-caffeine")
}.to output(/local-caffeine/).to_stdout
end
it "ignores hyphens in Cask tokens" do
expect {
Hbc::CLI::Search.run("googlechrome")
}.to output(/google-chrome/).to_stdout
Hbc::CLI::Search.run("localcaffeine")
}.to output(/local-caffeine/).to_stdout
end
it "accepts multiple arguments" do
expect {
Hbc::CLI::Search.run("google chrome")
}.to output(/google-chrome/).to_stdout
Hbc::CLI::Search.run("local caffeine")
}.to output(/local-caffeine/).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
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
}.to output("==> Regexp matches\nlocal-caffeine\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
Hbc::CLI::Search.run("test-opera")
}.to output(/^==> Exact match\ntest-opera\n==> Partial matches\ntest-opera-mail/).to_stdout
end
it "does not search the Tap name" do

View File

@ -9,13 +9,13 @@ describe Hbc::CLI::Uninstall do
it "shows an error when a Cask is provided that's not installed" do
expect {
Hbc::CLI::Uninstall.run("anvil")
Hbc::CLI::Uninstall.run("local-caffeine")
}.to raise_error(Hbc::CaskNotInstalledError)
end
it "tries anyway on a non-present Cask when --force is given" do
expect {
Hbc::CLI::Uninstall.run("anvil", "--force")
Hbc::CLI::Uninstall.run("local-caffeine", "--force")
}.not_to raise_error
end

View File

@ -1,4 +1,3 @@
require "pathname"
require "rspec/its"
require "rspec/wait"
@ -22,21 +21,16 @@ Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb"
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", "spec").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
HOMEBREW_CASK_DIRS = [
:appdir,
:caskroom,
:cache,
:prefpanedir,
:qlplugindir,
:servicedir,