summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler_spec.rb
diff options
context:
space:
mode:
authorGreg Werbin <spam@me.gregwerbin.com>2017-09-10 21:07:47 -0400
committerGreg Werbin <spam@me.gregwerbin.com>2017-09-10 21:07:47 -0400
commitd378a816866ce28f7fa010a4dd9095f4b2439bee (patch)
treefd70a55a16834a4b683cbbf945a765234e8fbba1 /spec/bundler/bundler_spec.rb
parentb241c53d1782745d694545000a7f4c251b243a1b (diff)
downloadbundler-d378a816866ce28f7fa010a4dd9095f4b2439bee.tar.gz
Use tests from the old commit
Mostly unmodified tests from PR 5787 (not linked here to respect contribution guidelines).
Diffstat (limited to 'spec/bundler/bundler_spec.rb')
-rw-r--r--spec/bundler/bundler_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 19e3f0336f..34011a21a6 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -227,4 +227,58 @@ EOF
expect(Bundler.tmp_home_path("USER", "")).to eq(Pathname("/TMP/bundler/home/USER"))
end
end
+
+ context "user cache dir" do
+ let(:home_path) { ENV.fetch "HOME" }
+ let(:bundle_user_cache_default) { "#{home_path}/.cache" }
+ let(:bundle_user_cache_custom) { "#{home_path}/User/cache" }
+ let(:fallback_dir) { "#{bundle_user_cache_default}/bundler" }
+ let(:cache_dir) { "#{bundle_user_cache_custom}/bundler" }
+ let(:legacy_cache_dir) { "#{home_path}/.bundle/cache" }
+
+ describe "#bundle_user_path_config" do
+ before do
+ allow(Bundler.rubygems).to receive(:user_home).and_return(home_path)
+ allow(File).to receive(:writable?).with(home_path).and_return(true)
+ allow(File).to receive(:directory?).with(home_path).and_return(true)
+ allow(File).to receive(:directory?).with(fallback_dir).and_return(true)
+ allow(File).to receive(:directory?).with(cache_dir).and_return(true)
+ end
+
+ it "should use the value of BUNDLE_USER_CACHE_HOME" do
+ ENV["BUNDLE_USER_CACHE_HOME"] = bundle_user_cache_custom
+ expect(Bundler.bundle_user_home("CACHE", fallback_dir)).to eq(Pathname(cache_dir))
+ end
+
+ it "should fall back to the alternative directory" do
+ expect(Bundler.bundle_user_home("CACHE", bundle_user_cache_default)).to eq(Pathname(fallback_dir))
+ end
+ end
+
+ describe "#user_cache" do
+ before do
+ allow(Bundler.rubygems).to receive(:user_home).and_return(home_path)
+ allow(File).to receive(:writable?).with(home_path).and_return(true)
+ allow(File).to receive(:directory?).with(home_path).and_return(true)
+ end
+
+ it "should use ~/.bundle/cache if it exists" do
+ allow(FileTest).to receive(:exist?).with(legacy_cache_dir).and_return(true)
+ expect(Bundler.user_cache).to eq(Pathname(legacy_cache_dir))
+ end
+
+ it "should use BUNDLE_USER_CACHE_HOME if set" do
+ allow(FileTest).to receive(:exist?).with(legacy_cache_dir).and_return(false)
+ allow(FileTest).to receive(:exist?).with(cache_dir).and_return(true)
+ ENV["BUNDLE_USER_CACHE_HOME"] = bundle_user_cache_custom
+ expect(Bundler.user_cache).to eq(Pathname(cache_dir))
+ end
+
+ it "should use ~/.cache/bundler as default cache path" do
+ allow(FileTest).to receive(:exist?).with(legacy_cache_dir).and_return(false)
+ allow(FileTest).to receive(:exist?).with(fallback_dir).and_return(true)
+ expect(Bundler.user_cache).to eq(Pathname(fallback_dir))
+ end
+ end
+ end
end