summaryrefslogtreecommitdiff
path: root/spec/bundler/shared_helpers_spec.rb
diff options
context:
space:
mode:
authorJames Wen <jrw2175@columbia.edu>2016-01-09 23:31:39 -0500
committerJames Wen <jrw2175@columbia.edu>2016-01-10 01:44:57 -0500
commit91b9df7020a9214219169ce2ccf77c1fbd540845 (patch)
treef0c1955391c7de4ae480459d0c9f518d7b159954 /spec/bundler/shared_helpers_spec.rb
parentd9aa33effe34755f81a957f3afb1e71fa97eee17 (diff)
downloadbundler-91b9df7020a9214219169ce2ccf77c1fbd540845.tar.gz
Add unit tests for `Bundler::SharedHelpers#with_clean_git_env`
- Add ENV['GIT_DIR'] and ENV['GIT_WORK_TREE'] to after-spec resets
Diffstat (limited to 'spec/bundler/shared_helpers_spec.rb')
-rw-r--r--spec/bundler/shared_helpers_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb
index 7dbfcbdedb..a72fc34a74 100644
--- a/spec/bundler/shared_helpers_spec.rb
+++ b/spec/bundler/shared_helpers_spec.rb
@@ -135,6 +135,51 @@ describe Bundler::SharedHelpers do
expect(subject.pwd).to eq(bundled_app)
end
end
+ describe "#with_clean_git_env" do
+ before do
+ ENV["GIT_DIR"] = "ORIGINAL_ENV_GIT_DIR"
+ ENV["GIT_WORK_TREE"] = "ORIGINAL_ENV_GIT_WORK_TREE"
+ end
+ it "executes the passed block" do
+ with_clean_git_env_block = proc do
+ Dir.mkdir "with_clean_git_env_test_dir"
+ end
+ subject.with_clean_git_env(&with_clean_git_env_block)
+ expect(Pathname.new("with_clean_git_env_test_dir")).to exist
+ end
+ it "uses a fresh git env for execution" do
+ with_clean_git_env_block = proc do
+ Dir.mkdir "git_dir_test_dir" unless ENV["GIT_DIR"].nil?
+ Dir.mkdir "git_work_tree_test_dir" unless ENV["GIT_WORK_TREE"].nil?
+ end
+ subject.with_clean_git_env(&with_clean_git_env_block)
+ expect(Pathname.new("git_dir_test_dir")).to_not exist
+ expect(Pathname.new("git_work_tree_test_dir")).to_not exist
+ end
+ context "passed block does not throw errors" do
+ it "restores the git env after" do
+ with_clean_git_env_block = proc do
+ ENV["GIT_DIR"] = "NEW_ENV_GIT_DIR"
+ ENV["GIT_WORK_TREE"] = "NEW_ENV_GIT_WORK_TREE"
+ end
+ subject.with_clean_git_env(&with_clean_git_env_block)
+ expect(ENV["GIT_DIR"]).to eq("ORIGINAL_ENV_GIT_DIR")
+ expect(ENV["GIT_WORK_TREE"]).to eq("ORIGINAL_ENV_GIT_WORK_TREE")
+ end
+ end
+ context "passed block throws errors" do
+ it "restores the git env after" do
+ with_clean_git_env_block = proc do
+ ENV["GIT_DIR"] = "NEW_ENV_GIT_DIR"
+ ENV["GIT_WORK_TREE"] = "NEW_ENV_GIT_WORK_TREE"
+ raise RuntimeError.new
+ end
+ expect { subject.with_clean_git_env(&with_clean_git_env_block) }.to raise_error(RuntimeError)
+ expect(ENV["GIT_DIR"]).to eq("ORIGINAL_ENV_GIT_DIR")
+ expect(ENV["GIT_WORK_TREE"]).to eq("ORIGINAL_ENV_GIT_WORK_TREE")
+ end
+ end
+ end
describe "#set_bundle_environment" do
shared_examples_for "ENV['PATH'] gets set correctly" do
before do