Make Cask tests work without tapping caskroom/cask.
				
					
				
			This commit is contained in:
		
							parent
							
								
									a1fbb1020b
								
							
						
					
					
						commit
						80be26fd8b
					
				@ -22,33 +22,33 @@ describe Hbc::Cask do
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "load" do
 | 
					  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
 | 
					    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).to be_kind_of(Hbc::Cask)
 | 
				
			||||||
      expect(c.token).to eq("adium")
 | 
					      expect(c.token).to eq("local-caffeine")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "returns an instance of the Cask from a specific file location" do
 | 
					    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("#{tap_path}/Casks/local-caffeine.rb")
 | 
				
			||||||
      c = Hbc.load(location)
 | 
					 | 
				
			||||||
      expect(c).to be_kind_of(Hbc::Cask)
 | 
					      expect(c).to be_kind_of(Hbc::Cask)
 | 
				
			||||||
      expect(c.token).to eq("dia")
 | 
					      expect(c.token).to eq("local-caffeine")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "returns an instance of the Cask from a url" do
 | 
					    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
 | 
					      c = shutup do
 | 
				
			||||||
        Hbc.load(url)
 | 
					        Hbc.load("file://#{tap_path}/Casks/local-caffeine.rb")
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      expect(c).to be_kind_of(Hbc::Cask)
 | 
					      expect(c).to be_kind_of(Hbc::Cask)
 | 
				
			||||||
      expect(c.token).to eq("dia")
 | 
					      expect(c.token).to eq("local-caffeine")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "raises an error when failing to download a Cask from a url" do
 | 
					    it "raises an error when failing to download a Cask from a url" do
 | 
				
			||||||
      expect {
 | 
					      expect {
 | 
				
			||||||
        url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/notacask.rb")
 | 
					        url = "file://#{tap_path}/Casks/notacask.rb"
 | 
				
			||||||
        shutup do
 | 
					        shutup do
 | 
				
			||||||
          Hbc.load(url)
 | 
					          Hbc.load(url)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
@ -56,9 +56,9 @@ describe Hbc::Cask do
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "returns an instance of the Cask from a relative file location" do
 | 
					    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).to be_kind_of(Hbc::Cask)
 | 
				
			||||||
      expect(c.token).to eq("bbedit")
 | 
					      expect(c.token).to eq("local-caffeine")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "uses exact match when loading by token" do
 | 
					    it "uses exact match when loading by token" do
 | 
				
			||||||
@ -83,7 +83,7 @@ describe Hbc::Cask do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  describe "metadata" do
 | 
					  describe "metadata" do
 | 
				
			||||||
    it "proposes a versioned metadata directory name for each instance" do
 | 
					    it "proposes a versioned metadata directory name for each instance" do
 | 
				
			||||||
      cask_token = "adium"
 | 
					      cask_token = "local-caffeine"
 | 
				
			||||||
      c = Hbc.load(cask_token)
 | 
					      c = Hbc.load(cask_token)
 | 
				
			||||||
      metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
 | 
					      metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
 | 
				
			||||||
      expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s)
 | 
					      expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s)
 | 
				
			||||||
 | 
				
			|||||||
@ -64,21 +64,21 @@ describe Hbc::CLI::Install do
 | 
				
			|||||||
  it "returns a suggestion for a misspelled Cask" do
 | 
					  it "returns a suggestion for a misspelled Cask" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        Hbc::CLI::Install.run("googlechrome")
 | 
					        Hbc::CLI::Install.run("localcaffeine")
 | 
				
			||||||
      rescue Hbc::CaskError
 | 
					      rescue Hbc::CaskError
 | 
				
			||||||
        nil
 | 
					        nil
 | 
				
			||||||
      end
 | 
					      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
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "returns multiple suggestions for a Cask fragment" do
 | 
					  it "returns multiple suggestions for a Cask fragment" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        Hbc::CLI::Install.run("google")
 | 
					        Hbc::CLI::Install.run("local-caf")
 | 
				
			||||||
      rescue Hbc::CaskError
 | 
					      rescue Hbc::CaskError
 | 
				
			||||||
        nil
 | 
					        nil
 | 
				
			||||||
      end
 | 
					      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
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "when no Cask is specified" do
 | 
					  describe "when no Cask is specified" do
 | 
				
			||||||
 | 
				
			|||||||
@ -3,11 +3,11 @@ require "spec_helper"
 | 
				
			|||||||
describe Hbc::CLI::Search do
 | 
					describe Hbc::CLI::Search do
 | 
				
			||||||
  it "lists the available Casks that match the search term" do
 | 
					  it "lists the available Casks that match the search term" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("photoshop")
 | 
					      Hbc::CLI::Search.run("local")
 | 
				
			||||||
    }.to output(<<-EOS.undent).to_stdout
 | 
					    }.to output(<<-EOS.undent).to_stdout
 | 
				
			||||||
      ==> Partial matches
 | 
					      ==> Partial matches
 | 
				
			||||||
      adobe-photoshop-cc
 | 
					      local-caffeine
 | 
				
			||||||
      adobe-photoshop-lightroom
 | 
					      local-transmission
 | 
				
			||||||
    EOS
 | 
					    EOS
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,37 +20,37 @@ describe Hbc::CLI::Search do
 | 
				
			|||||||
  it "lists all available Casks with no search term" do
 | 
					  it "lists all available Casks with no search term" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run
 | 
					      Hbc::CLI::Search.run
 | 
				
			||||||
    }.to output(/google-chrome/).to_stdout
 | 
					    }.to output(/local-caffeine/).to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "ignores hyphens in search terms" do
 | 
					  it "ignores hyphens in search terms" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("goo-gle-chrome")
 | 
					      Hbc::CLI::Search.run("lo-cal-caffeine")
 | 
				
			||||||
    }.to output(/google-chrome/).to_stdout
 | 
					    }.to output(/local-caffeine/).to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "ignores hyphens in Cask tokens" do
 | 
					  it "ignores hyphens in Cask tokens" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("googlechrome")
 | 
					      Hbc::CLI::Search.run("localcaffeine")
 | 
				
			||||||
    }.to output(/google-chrome/).to_stdout
 | 
					    }.to output(/local-caffeine/).to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "accepts multiple arguments" do
 | 
					  it "accepts multiple arguments" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("google chrome")
 | 
					      Hbc::CLI::Search.run("local caffeine")
 | 
				
			||||||
    }.to output(/google-chrome/).to_stdout
 | 
					    }.to output(/local-caffeine/).to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "accepts a regexp argument" do
 | 
					  it "accepts a regexp argument" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("/^google-c[a-z]rome$/")
 | 
					      Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
 | 
				
			||||||
    }.to output("==> Regexp matches\ngoogle-chrome\n").to_stdout
 | 
					    }.to output("==> Regexp matches\nlocal-caffeine\n").to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "Returns both exact and partial matches" do
 | 
					  it "Returns both exact and partial matches" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Search.run("mnemosyne")
 | 
					      Hbc::CLI::Search.run("test-opera")
 | 
				
			||||||
    }.to output(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/).to_stdout
 | 
					    }.to output(/^==> Exact match\ntest-opera\n==> Partial matches\ntest-opera-mail/).to_stdout
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "does not search the Tap name" do
 | 
					  it "does not search the Tap name" do
 | 
				
			||||||
 | 
				
			|||||||
@ -9,13 +9,13 @@ describe Hbc::CLI::Uninstall do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  it "shows an error when a Cask is provided that's not installed" do
 | 
					  it "shows an error when a Cask is provided that's not installed" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Uninstall.run("anvil")
 | 
					      Hbc::CLI::Uninstall.run("local-caffeine")
 | 
				
			||||||
    }.to raise_error(Hbc::CaskNotInstalledError)
 | 
					    }.to raise_error(Hbc::CaskNotInstalledError)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "tries anyway on a non-present Cask when --force is given" do
 | 
					  it "tries anyway on a non-present Cask when --force is given" do
 | 
				
			||||||
    expect {
 | 
					    expect {
 | 
				
			||||||
      Hbc::CLI::Uninstall.run("anvil", "--force")
 | 
					      Hbc::CLI::Uninstall.run("local-caffeine", "--force")
 | 
				
			||||||
    }.not_to raise_error
 | 
					    }.not_to raise_error
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -27,9 +27,6 @@ Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
 | 
				
			|||||||
  FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
 | 
					  FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
 | 
				
			||||||
end
 | 
					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 = [
 | 
					HOMEBREW_CASK_DIRS = [
 | 
				
			||||||
  :appdir,
 | 
					  :appdir,
 | 
				
			||||||
  :caskroom,
 | 
					  :caskroom,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user