diff options
Diffstat (limited to 'Library/Homebrew/test')
5 files changed, 100 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index a6ecc207f..5858a7c6d 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -171,4 +171,38 @@ describe Hbc::Cask, :cask do end end end + + describe "full_name" do + context "when it is a core cask" do + it "is the cask token" do + c = Hbc::CaskLoader.load("local-caffeine") + expect(c.full_name).to eq("local-caffeine") + end + end + + context "when it is from a non-core tap" do + it "returns the fully-qualified name of the cask" do + c = Hbc::CaskLoader.load("third-party/tap/third-party-cask") + expect(c.full_name).to eq("third-party/tap/third-party-cask") + end + end + + context "when it is from no known tap" do + it "retuns the cask token" do + file = Tempfile.new(%w[tapless-cask .rb]) + + begin + cask_name = File.basename(file.path, ".rb") + file.write "cask '#{cask_name}'" + file.close + + c = Hbc::CaskLoader.load(file.path) + expect(c.full_name).to eq(cask_name) + ensure + file.close + file.unlink + end + end + end + end end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index fd6997f41..d2d7efd3b 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -14,6 +14,26 @@ describe Hbc::CLI::List, :cask do EOS end + it "lists full names" do + casks = %w[ + local-caffeine + third-party/tap/third-party-cask + local-transmission + ].map { |c| Hbc::CaskLoader.load(c) } + + casks.each do |c| + InstallHelper.install_with_caskfile(c) + end + + expect { + Hbc::CLI::List.run("--full-name") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + third-party/tap/third-party-cask + EOS + end + describe "lists versions" do let(:casks) { ["local-caffeine", "local-transmission"] } let(:expected_output) { diff --git a/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb new file mode 100644 index 000000000..d7add0522 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb @@ -0,0 +1,9 @@ +cask 'third-party-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/ThirdParty.dmg' + homepage 'http://example.com/' + + app 'ThirdParty.app' +end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index c51d339a7..fc83149d0 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -18,6 +18,7 @@ HOMEBREW_CASK_DIRS = [ RSpec.shared_context "Homebrew-Cask" do around(:each) do |example| + third_party_tap = Tap.fetch("third-party", "tap") begin dirs = HOMEBREW_CASK_DIRS.map do |dir| Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path| @@ -31,11 +32,18 @@ RSpec.shared_context "Homebrew-Cask" do FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path end + third_party_tap.tap do |tap| + FileUtils.mkdir_p tap.path.dirname + FileUtils.ln_sf TEST_FIXTURE_DIR.join("third-party"), tap.path + end + example.run ensure FileUtils.rm_rf dirs Hbc.default_tap.path.unlink FileUtils.rm_rf Hbc.default_tap.path.parent + third_party_tap.path.unlink + FileUtils.rm_rf third_party_tap.path.parent end end end diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 37bd83c4f..3b5355b15 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -296,4 +296,33 @@ describe "globally-scoped helper methods" do expect(ENV["PATH"]).not_to eq("/bin") end end + + describe "#tap_and_name_comparison" do + describe "both strings are only names" do + it "alphabetizes the strings" do + expect(%w[a b].sort(&tap_and_name_comparison)).to eq(%w[a b]) + expect(%w[b a].sort(&tap_and_name_comparison)).to eq(%w[a b]) + end + end + + describe "both strings include tap" do + it "alphabetizes the strings" do + expect(%w[a/z/z b/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + expect(%w[b/z/z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + + expect(%w[z/a/z z/b/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + expect(%w[z/b/z z/a/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + + expect(%w[z/z/a z/z/b].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + expect(%w[z/z/b z/z/a].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + end + end + + describe "only one string includes tap" do + it "prefers the string without tap" do + expect(%w[a/z/z z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + expect(%w[z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + end + end + end end |
