aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-28 14:50:46 +0100
committerMarkus Reiter2017-02-28 15:06:32 +0100
commita5549023804a8cef50f71dc2d7a723be8e83f3d1 (patch)
tree0c5bcf473909f755d209793892a21ce40f6bdd07
parent0457f0d3e2186991c16e2136b12a5ecc034d99da (diff)
downloadbrew-a5549023804a8cef50f71dc2d7a723be8e83f3d1.tar.bz2
Add `mktmpdir` helper method.
-rw-r--r--Library/Homebrew/test/cmd/bundle_spec.rb4
-rw-r--r--Library/Homebrew/test/cmd/commands_spec.rb2
-rw-r--r--Library/Homebrew/test/cmd/custom-external-command_spec.rb4
-rw-r--r--Library/Homebrew/test/cmd/linkapps_spec.rb6
-rw-r--r--Library/Homebrew/test/cmd/unlinkapps_spec.rb6
-rw-r--r--Library/Homebrew/test/cmd/unpack_spec.rb4
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb12
-rw-r--r--Library/Homebrew/test/diagnostic_spec.rb14
-rw-r--r--Library/Homebrew/test/gpg2_requirement_spec.rb6
-rw-r--r--Library/Homebrew/test/gpg_spec.rb3
-rw-r--r--Library/Homebrew/test/java_requirement_spec.rb6
-rw-r--r--Library/Homebrew/test/language/go_spec.rb2
-rw-r--r--Library/Homebrew/test/language/python_spec.rb4
-rw-r--r--Library/Homebrew/test/os/mac/java_requirement_spec.rb17
-rw-r--r--Library/Homebrew/test/pathname_spec.rb8
-rw-r--r--Library/Homebrew/test/sandbox_spec.rb6
-rw-r--r--Library/Homebrew/test/spec_helper.rb2
-rw-r--r--Library/Homebrew/test/support/helper/mktmpdir.rb11
-rw-r--r--Library/Homebrew/test/utils_spec.rb7
19 files changed, 47 insertions, 77 deletions
diff --git a/Library/Homebrew/test/cmd/bundle_spec.rb b/Library/Homebrew/test/cmd/bundle_spec.rb
index 755f9ab3d..13f13485c 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 32d07a0bc..cf6f56740 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 8ccc21fa7..d649786ec 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 42118a215..2bca97822 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 1e21bd851..e1170f435 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 244fc0852..9b2b801bc 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 c4afe6592..ec1a34fb4 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 e749a3b0f..59560127c 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 f46b31196..d7767abd3 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 9809dccb5..aa00d79f5 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 5adf64c7c..05d4f3cda 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 24db78594..fb8c97829 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 c78520897..02f6bf8d2 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 f6404db92..1b46fe6b6 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 21e14479f..77cb6cfed 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 98634bf3c..0d349f6eb 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 7905142a8..122aaba46 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 000000000..f08fd386b
--- /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 b3fdedcb9..90eed7d88 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")