Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Cask tests work without tapping caskroom/cask. #2256

Merged
merged 2 commits into from Mar 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Library/Homebrew/cask/lib/hbc/locations.rb
Expand Up @@ -15,6 +15,8 @@ def default_caskroom
@default_caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end

attr_writer :caskroom

def caskroom
@caskroom ||= begin
if Utils.path_occupied?(legacy_caskroom)
Expand All @@ -36,14 +38,12 @@ def caskroom
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
Expand Down
26 changes: 13 additions & 13 deletions Library/Homebrew/cask/spec/cask/cask_spec.rb
Expand Up @@ -22,43 +22,43 @@
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
}.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")
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
Expand All @@ -83,7 +83,7 @@

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)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/cask/spec/cask/cli/install_spec.rb
Expand Up @@ -64,21 +64,21 @@
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
Expand Down
28 changes: 14 additions & 14 deletions Library/Homebrew/cask/spec/cask/cli/search_spec.rb
Expand Up @@ -3,11 +3,11 @@
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

Expand All @@ -20,37 +20,37 @@
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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
Expand Up @@ -9,13 +9,13 @@

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

Expand Down
8 changes: 1 addition & 7 deletions Library/Homebrew/cask/spec/spec_helper.rb
@@ -1,4 +1,3 @@
require "pathname"
require "rspec/its"
require "rspec/wait"

Expand All @@ -22,21 +21,16 @@
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,
Expand Down