Merge pull request #2232 from reitermarkus/spec-mktmpdir
Add `mktmpdir` helper method.
This commit is contained in:
		
						commit
						fa34aa2a21
					
				@ -10,9 +10,9 @@ describe "brew bundle", :integration_test, :needs_test_cmd_taps do
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      Dir.mktmpdir do |path|
 | 
			
		||||
      mktmpdir do |path|
 | 
			
		||||
        FileUtils.touch "#{path}/Brewfile"
 | 
			
		||||
        Dir.chdir path do
 | 
			
		||||
        path.cd do
 | 
			
		||||
          expect { brew "bundle", "check" }
 | 
			
		||||
            .to output("The Brewfile's dependencies are satisfied.\n").to_stdout
 | 
			
		||||
            .and not_to_output.to_stderr
 | 
			
		||||
 | 
			
		||||
@ -54,7 +54,7 @@ describe Homebrew do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "::external_commands" do
 | 
			
		||||
    Dir.mktmpdir do |dir|
 | 
			
		||||
    mktmpdir do |dir|
 | 
			
		||||
      %w[brew-t1 brew-t2.rb brew-t3.py].each do |file|
 | 
			
		||||
        path = "#{dir}/#{file}"
 | 
			
		||||
        FileUtils.touch path
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,6 @@
 | 
			
		||||
describe "brew custom-external-command", :integration_test do
 | 
			
		||||
  it "is supported" do
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
      path = Pathname.new(path)
 | 
			
		||||
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      cmd = "custom-external-command-#{rand}"
 | 
			
		||||
      file = path/"brew-#{cmd}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,7 @@
 | 
			
		||||
describe "brew linkapps", :integration_test do
 | 
			
		||||
  let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:home_dir) { mktmpdir }
 | 
			
		||||
  let(:apps_dir) { home_dir/"Applications" }
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    home_dir.rmtree unless @home_dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "symlinks applications" do
 | 
			
		||||
    apps_dir.mkpath
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,7 @@
 | 
			
		||||
describe "brew unlinkapps", :integration_test do
 | 
			
		||||
  let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:home_dir) { mktmpdir }
 | 
			
		||||
  let(:apps_dir) { home_dir/"Applications" }
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    home_dir.rmtree unless @home_dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "unlinks symlinked applications" do
 | 
			
		||||
    apps_dir.mkpath
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,9 +2,7 @@ describe "brew unpack", :integration_test do
 | 
			
		||||
  it "unpacks a given Formula's archive" do
 | 
			
		||||
    setup_test_formula "testball"
 | 
			
		||||
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
      path = Pathname.new(path)
 | 
			
		||||
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      shutup do
 | 
			
		||||
        expect { brew "unpack", "testball", "--destdir=#{path}" }
 | 
			
		||||
          .to be_a_success
 | 
			
		||||
 | 
			
		||||
@ -6,11 +6,7 @@ RSpec::Matchers.alias_matcher :have_end, :be_end
 | 
			
		||||
RSpec::Matchers.alias_matcher :have_trailing_newline, :be_trailing_newline
 | 
			
		||||
 | 
			
		||||
describe FormulaText do
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    dir.rmtree unless @dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  def formula_text(name, body = nil, options = {})
 | 
			
		||||
    path = dir/"#{name}.rb"
 | 
			
		||||
@ -70,11 +66,7 @@ describe FormulaAuditor do
 | 
			
		||||
    described_class.new(Formulary.factory(path), options)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    dir.rmtree unless @dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  describe "#problems" do
 | 
			
		||||
    it "is empty by default" do
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#check_for_anaconda" do
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      anaconda = "#{path}/anaconda"
 | 
			
		||||
      python = "#{path}/python"
 | 
			
		||||
      FileUtils.touch anaconda
 | 
			
		||||
@ -23,7 +23,7 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
      FileUtils.chmod 0755, anaconda
 | 
			
		||||
      FileUtils.chmod 0755, python
 | 
			
		||||
 | 
			
		||||
      ENV["PATH"] = path + File::PATH_SEPARATOR + ENV["PATH"]
 | 
			
		||||
      ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
 | 
			
		||||
 | 
			
		||||
      expect(subject.check_for_anaconda).to match("Anaconda")
 | 
			
		||||
    end
 | 
			
		||||
@ -124,7 +124,7 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#check_user_curlrc" do
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      FileUtils.touch "#{path}/.curlrc"
 | 
			
		||||
      ENV["CURL_HOME"] = path
 | 
			
		||||
 | 
			
		||||
@ -133,7 +133,7 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#check_for_config_scripts" do
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      file = "#{path}/foo-config"
 | 
			
		||||
      FileUtils.touch file
 | 
			
		||||
      FileUtils.chmod 0755, file
 | 
			
		||||
@ -153,7 +153,7 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
    begin
 | 
			
		||||
      HOMEBREW_CELLAR.rmtree
 | 
			
		||||
 | 
			
		||||
      Dir.mktmpdir do |path|
 | 
			
		||||
      mktmpdir do |path|
 | 
			
		||||
        FileUtils.ln_s path, HOMEBREW_CELLAR
 | 
			
		||||
 | 
			
		||||
        expect(subject.check_for_symlinked_cellar).to match(path)
 | 
			
		||||
@ -170,8 +170,8 @@ describe Homebrew::Diagnostic::Checks do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#check_for_external_cmd_name_conflict" do
 | 
			
		||||
    Dir.mktmpdir do |path1|
 | 
			
		||||
      Dir.mktmpdir do |path2|
 | 
			
		||||
    mktmpdir do |path1|
 | 
			
		||||
      mktmpdir do |path2|
 | 
			
		||||
        [path1, path2].each do |path|
 | 
			
		||||
          cmd = "#{path}/brew-foo"
 | 
			
		||||
          FileUtils.touch cmd
 | 
			
		||||
 | 
			
		||||
@ -2,11 +2,7 @@ require "requirements/gpg2_requirement"
 | 
			
		||||
require "fileutils"
 | 
			
		||||
 | 
			
		||||
describe GPG2Requirement do
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    FileUtils.rm_rf dir unless @dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  describe "#satisfied?" do
 | 
			
		||||
    it "returns true if GPG2 is installed" do
 | 
			
		||||
 | 
			
		||||
@ -7,9 +7,8 @@ describe Gpg do
 | 
			
		||||
    it "creates a test key in the home directory" do
 | 
			
		||||
      skip "GPG Unavailable" unless subject.available?
 | 
			
		||||
 | 
			
		||||
      Dir.mktmpdir do |dir|
 | 
			
		||||
      mktmpdir do |dir|
 | 
			
		||||
        ENV["HOME"] = dir
 | 
			
		||||
        dir = Pathname.new(dir)
 | 
			
		||||
 | 
			
		||||
        shutup do
 | 
			
		||||
          subject.create_test_key(dir)
 | 
			
		||||
 | 
			
		||||
@ -46,7 +46,7 @@ describe JavaRequirement do
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context "when #possible_javas contains paths" do
 | 
			
		||||
      let(:path) { Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
      let(:path) { mktmpdir }
 | 
			
		||||
      let(:java) { path/"java" }
 | 
			
		||||
 | 
			
		||||
      def setup_java_with_version(version)
 | 
			
		||||
@ -61,10 +61,6 @@ describe JavaRequirement do
 | 
			
		||||
        allow(subject).to receive(:possible_javas).and_return([java])
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      after(:each) do
 | 
			
		||||
        path.rmtree
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "and 1.7 is required" do
 | 
			
		||||
        subject { described_class.new(%w[1.7]) }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ describe Language::Go do
 | 
			
		||||
 | 
			
		||||
    expect(described_class).to receive(:opoo).once
 | 
			
		||||
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      shutup do
 | 
			
		||||
        described_class.stage_deps [], path
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
@ -4,14 +4,12 @@ require "resource"
 | 
			
		||||
describe Language::Python::Virtualenv::Virtualenv do
 | 
			
		||||
  subject { described_class.new(formula, dir, "python") }
 | 
			
		||||
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  let(:resource) { double("resource", stage: true) }
 | 
			
		||||
  let(:formula_bin) { dir/"formula_bin" }
 | 
			
		||||
  let(:formula) { double("formula", resource: resource, bin: formula_bin) }
 | 
			
		||||
 | 
			
		||||
  after(:each) { dir.rmtree unless @dir.nil? }
 | 
			
		||||
 | 
			
		||||
  describe "#create" do
 | 
			
		||||
    it "creates a virtual environment" do
 | 
			
		||||
      expect(formula).to receive(:resource).with("homebrew-virtualenv").and_return(resource)
 | 
			
		||||
 | 
			
		||||
@ -3,32 +3,29 @@ require "fileutils"
 | 
			
		||||
 | 
			
		||||
describe JavaRequirement do
 | 
			
		||||
  subject { described_class.new(%w[1.8]) }
 | 
			
		||||
  let(:java_home) { Dir.mktmpdir }
 | 
			
		||||
  let(:java_home_path) { Pathname.new(java_home) }
 | 
			
		||||
  let(:java_home) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  before(:each) do
 | 
			
		||||
    FileUtils.mkdir java_home_path/"bin"
 | 
			
		||||
    FileUtils.touch java_home_path/"bin/java"
 | 
			
		||||
    allow(subject).to receive(:preferred_java).and_return(java_home_path/"bin/java")
 | 
			
		||||
    FileUtils.mkdir java_home/"bin"
 | 
			
		||||
    FileUtils.touch java_home/"bin/java"
 | 
			
		||||
    allow(subject).to receive(:preferred_java).and_return(java_home/"bin/java")
 | 
			
		||||
    expect(subject).to be_satisfied
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  after(:each) { java_home_path.rmtree }
 | 
			
		||||
 | 
			
		||||
  specify "Apple Java environment" do
 | 
			
		||||
    expect(ENV).to receive(:prepend_path)
 | 
			
		||||
    expect(ENV).to receive(:append_to_cflags)
 | 
			
		||||
 | 
			
		||||
    subject.modify_build_environment
 | 
			
		||||
    expect(ENV["JAVA_HOME"]).to eq(java_home)
 | 
			
		||||
    expect(ENV["JAVA_HOME"]).to eq(java_home.to_s)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "Oracle Java environment" do
 | 
			
		||||
    FileUtils.mkdir java_home_path/"include"
 | 
			
		||||
    FileUtils.mkdir java_home/"include"
 | 
			
		||||
    expect(ENV).to receive(:prepend_path)
 | 
			
		||||
    expect(ENV).to receive(:append_to_cflags).twice
 | 
			
		||||
 | 
			
		||||
    subject.modify_build_environment
 | 
			
		||||
    expect(ENV["JAVA_HOME"]).to eq(java_home)
 | 
			
		||||
    expect(ENV["JAVA_HOME"]).to eq(java_home.to_s)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -5,13 +5,11 @@ require "install_renamed"
 | 
			
		||||
describe Pathname do
 | 
			
		||||
  include FileUtils
 | 
			
		||||
 | 
			
		||||
  let(:src) { Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:dst) { Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:src) { mktmpdir }
 | 
			
		||||
  let(:dst) { mktmpdir }
 | 
			
		||||
  let(:file) { src/"foo" }
 | 
			
		||||
  let(:dir) { src/"bar" }
 | 
			
		||||
 | 
			
		||||
  after(:each) { rm_rf [src, dst] }
 | 
			
		||||
 | 
			
		||||
  describe DiskUsageExtension do
 | 
			
		||||
    before(:each) do
 | 
			
		||||
      mkdir_p dir/"a-directory"
 | 
			
		||||
@ -294,7 +292,7 @@ describe Pathname do
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe FileUtils do
 | 
			
		||||
  let(:dst) { Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:dst) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  describe "#mkdir" do
 | 
			
		||||
    it "creates indermediate directories" do
 | 
			
		||||
 | 
			
		||||
@ -3,17 +3,13 @@ require "sandbox"
 | 
			
		||||
RSpec::Matchers.define_negated_matcher :not_matching, :matching
 | 
			
		||||
 | 
			
		||||
describe Sandbox do
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
  let(:file) { dir/"foo" }
 | 
			
		||||
 | 
			
		||||
  before(:each) do
 | 
			
		||||
    skip "Sandbox not implemented." unless described_class.available?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  after(:each) do
 | 
			
		||||
    dir.rmtree unless @dir.nil?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#formula?" do
 | 
			
		||||
    f = formula { url "foo-1.0" }
 | 
			
		||||
    f2 = formula { url "bar-1.0" }
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,7 @@ require "tap"
 | 
			
		||||
require "test/support/helper/shutup"
 | 
			
		||||
require "test/support/helper/fixtures"
 | 
			
		||||
require "test/support/helper/formula"
 | 
			
		||||
require "test/support/helper/mktmpdir"
 | 
			
		||||
require "test/support/helper/spec/shared_context/integration_test"
 | 
			
		||||
 | 
			
		||||
TEST_DIRECTORIES = [
 | 
			
		||||
@ -35,6 +36,7 @@ RSpec.configure do |config|
 | 
			
		||||
  config.include(Test::Helper::Shutup)
 | 
			
		||||
  config.include(Test::Helper::Fixtures)
 | 
			
		||||
  config.include(Test::Helper::Formula)
 | 
			
		||||
  config.include(Test::Helper::MkTmpDir)
 | 
			
		||||
 | 
			
		||||
  config.before(:each, :needs_compat) do
 | 
			
		||||
    skip "Requires compatibility layer." if ENV["HOMEBREW_NO_COMPAT"]
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								Library/Homebrew/test/support/helper/mktmpdir.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Library/Homebrew/test/support/helper/mktmpdir.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
module Test
 | 
			
		||||
  module Helper
 | 
			
		||||
    module MkTmpDir
 | 
			
		||||
      def mktmpdir(prefix_suffix = nil)
 | 
			
		||||
        new_dir = Pathname.new(Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP))
 | 
			
		||||
        return yield new_dir if block_given?
 | 
			
		||||
        new_dir
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -1,9 +1,7 @@
 | 
			
		||||
require "utils"
 | 
			
		||||
 | 
			
		||||
describe "globally-scoped helper methods" do
 | 
			
		||||
  let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
 | 
			
		||||
 | 
			
		||||
  after(:each) { dir.rmtree unless @dir.nil? }
 | 
			
		||||
  let(:dir) { mktmpdir }
 | 
			
		||||
 | 
			
		||||
  def esc(code)
 | 
			
		||||
    /(\e\[\d+m)*\e\[#{code}m/
 | 
			
		||||
@ -195,8 +193,7 @@ describe "globally-scoped helper methods" do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  specify "#gzip" do
 | 
			
		||||
    Dir.mktmpdir do |path|
 | 
			
		||||
      path = Pathname.new(path)
 | 
			
		||||
    mktmpdir do |path|
 | 
			
		||||
      somefile = path/"somefile"
 | 
			
		||||
      FileUtils.touch somefile
 | 
			
		||||
      expect(gzip(somefile)[0].to_s).to eq("#{somefile}.gz")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user