diff --git a/Library/Homebrew/test/cmd/bundle_spec.rb b/Library/Homebrew/test/cmd/bundle_spec.rb index 755f9ab3d836b2620bca1f8839ba6a760380486e..13f13485ce35d79efc39a2f13a4da2f5c0c45508 100644 --- a/Library/Homebrew/test/cmd/bundle_spec.rb +++ b/Library/Homebrew/test/cmd/bundle_spec.rb @@ -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 diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index 32d07a0bc0631e09f1c92dac9cbf4ae323de9b65..cf6f56740401e60920ab4101bc08426519c1ff02 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -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 diff --git a/Library/Homebrew/test/cmd/custom-external-command_spec.rb b/Library/Homebrew/test/cmd/custom-external-command_spec.rb index 8ccc21fa791c0cd0bc67071c613570feddeb951a..d649786ec88e9e6d04e4d67b36e55a1a335d0d91 100644 --- a/Library/Homebrew/test/cmd/custom-external-command_spec.rb +++ b/Library/Homebrew/test/cmd/custom-external-command_spec.rb @@ -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}" diff --git a/Library/Homebrew/test/cmd/linkapps_spec.rb b/Library/Homebrew/test/cmd/linkapps_spec.rb index 42118a215e21f9dc8fdad47070385a9f18bf4068..2bca97822878b9ba4ea7d7ab7119fef00c468e5b 100644 --- a/Library/Homebrew/test/cmd/linkapps_spec.rb +++ b/Library/Homebrew/test/cmd/linkapps_spec.rb @@ -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 diff --git a/Library/Homebrew/test/cmd/unlinkapps_spec.rb b/Library/Homebrew/test/cmd/unlinkapps_spec.rb index 1e21bd851a2f67df48002a4deb8b68c84b12a19b..e1170f435553014bf32242b40cdc6170c617445d 100644 --- a/Library/Homebrew/test/cmd/unlinkapps_spec.rb +++ b/Library/Homebrew/test/cmd/unlinkapps_spec.rb @@ -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 diff --git a/Library/Homebrew/test/cmd/unpack_spec.rb b/Library/Homebrew/test/cmd/unpack_spec.rb index 244fc0852287f5156f4ba582a754612e15c85e2d..9b2b801bc1f6b3571397976ff014f7e24eba0a91 100644 --- a/Library/Homebrew/test/cmd/unpack_spec.rb +++ b/Library/Homebrew/test/cmd/unpack_spec.rb @@ -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 diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index c4afe65924312c4fce13fda91fd42d7964d45328..ec1a34fb4a7a348036fed2a371f6189128523d39 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -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 diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb index e749a3b0f488af2dcfbd0f407bed945b57886814..59560127cb6042e7aa613a23dc27c7c492ad701d 100644 --- a/Library/Homebrew/test/diagnostic_spec.rb +++ b/Library/Homebrew/test/diagnostic_spec.rb @@ -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 diff --git a/Library/Homebrew/test/gpg2_requirement_spec.rb b/Library/Homebrew/test/gpg2_requirement_spec.rb index f46b31196fbd09cad9fe954381600cf4df059fd3..d7767abd3366f5e435fdef0bd0459a65ea140523 100644 --- a/Library/Homebrew/test/gpg2_requirement_spec.rb +++ b/Library/Homebrew/test/gpg2_requirement_spec.rb @@ -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 diff --git a/Library/Homebrew/test/gpg_spec.rb b/Library/Homebrew/test/gpg_spec.rb index 9809dccb5eec5b9401808ed5bfde5740ae22260d..aa00d79f514885e98a92e3ad95e55222f01e95a2 100644 --- a/Library/Homebrew/test/gpg_spec.rb +++ b/Library/Homebrew/test/gpg_spec.rb @@ -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) diff --git a/Library/Homebrew/test/java_requirement_spec.rb b/Library/Homebrew/test/java_requirement_spec.rb index 5adf64c7c2d943630b520f11ea3b21c2f5a4a69a..05d4f3cdacad0c6a84fc2d3787b5e04d78cd1d29 100644 --- a/Library/Homebrew/test/java_requirement_spec.rb +++ b/Library/Homebrew/test/java_requirement_spec.rb @@ -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]) } diff --git a/Library/Homebrew/test/language/go_spec.rb b/Library/Homebrew/test/language/go_spec.rb index 24db78594fb419ee6699c153ec7be2a11c63d9f4..fb8c978294ee713c18cfea347dcec612e163f75b 100644 --- a/Library/Homebrew/test/language/go_spec.rb +++ b/Library/Homebrew/test/language/go_spec.rb @@ -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 diff --git a/Library/Homebrew/test/language/python_spec.rb b/Library/Homebrew/test/language/python_spec.rb index c785208977ac6f74c3e33afbe134e5ab6a7e6e0f..02f6bf8d2473a04b8a5259476c19cf4b86f5d47a 100644 --- a/Library/Homebrew/test/language/python_spec.rb +++ b/Library/Homebrew/test/language/python_spec.rb @@ -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) diff --git a/Library/Homebrew/test/os/mac/java_requirement_spec.rb b/Library/Homebrew/test/os/mac/java_requirement_spec.rb index f6404db926c4311ff8505bc7ada6362a5c422088..1b46fe6b64ac598c28ec9129d40c15479c6a0bc6 100644 --- a/Library/Homebrew/test/os/mac/java_requirement_spec.rb +++ b/Library/Homebrew/test/os/mac/java_requirement_spec.rb @@ -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 diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb index 21e14479f025226c1856e096dc7e339532d556b2..77cb6cfed18688060400428c369b2c4fbb86a68f 100644 --- a/Library/Homebrew/test/pathname_spec.rb +++ b/Library/Homebrew/test/pathname_spec.rb @@ -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 diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb index 98634bf3cf2405a13bbe42d88d4dea98f1a468a3..0d349f6eb5a8a3bbde9516417eb3e50e2f828975 100644 --- a/Library/Homebrew/test/sandbox_spec.rb +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -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" } diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 7905142a80ede3a013865c0e5c0d59c2034a6ea9..122aaba46d210a801887e6942bd02b2ec422739c 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -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"] diff --git a/Library/Homebrew/test/support/helper/mktmpdir.rb b/Library/Homebrew/test/support/helper/mktmpdir.rb new file mode 100644 index 0000000000000000000000000000000000000000..f08fd386b470e0af55750d8115d251c60e1deb91 --- /dev/null +++ b/Library/Homebrew/test/support/helper/mktmpdir.rb @@ -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 diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index b3fdedcb985fea3031ca58a2b1caa81c6c544a5f..90eed7d88a6f0a5294da0885aaa8c78ddf3b2365 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -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")