diff options
author | fotanus@gmail.com <Felipe Tanus> | 2015-05-14 11:59:07 -0300 |
---|---|---|
committer | fotanus@gmail.com <Felipe Tanus> | 2015-05-14 11:59:07 -0300 |
commit | 7a69147a9c566d840242f1d36bef809925ee5154 (patch) | |
tree | 19a8464247f25ed4300154e75c5e56a20cc71b35 | |
parent | 2a81add2e61da212fd229e37461be21c02fe1a96 (diff) | |
download | bundler-7a69147a9c566d840242f1d36bef809925ee5154.tar.gz |
Recover correctly the env values
-rw-r--r-- | spec/bundler/fetcher_spec.rb | 20 | ||||
-rw-r--r-- | spec/support/helpers.rb | 12 |
2 files changed, 21 insertions, 11 deletions
diff --git a/spec/bundler/fetcher_spec.rb b/spec/bundler/fetcher_spec.rb index d5fb97b32f..3c7bef39f2 100644 --- a/spec/bundler/fetcher_spec.rb +++ b/spec/bundler/fetcher_spec.rb @@ -19,20 +19,18 @@ describe Bundler::Fetcher do describe "include CI information" do it "from one CI" do - ENV["JENKINS_URL"] = "foo" - ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} - expect(ci_part).to match("jenkins") - ENV["JENKINS_URL"] = nil + with_env_vars({"JENKINS_URL" => "foo"}) do + ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} + expect(ci_part).to match("jenkins") + end end it "from many CI" do - ENV["TRAVIS"] = "foo" - ENV["CI_NAME"] = "my_ci" - ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} - expect(ci_part).to match("travis") - expect(ci_part).to match("my_ci") - ENV["TRAVIS"] = nil - ENV["CI_NAME"] = nil + with_env_vars({"TRAVIS" => "foo", "CI_NAME" => "my_ci"}) do + ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} + expect(ci_part).to match("travis") + expect(ci_part).to match("my_ci") + end end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 6d7e9dfbe2..c1d9bfc28c 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -357,5 +357,17 @@ module Spec end File.open(pathname, 'w') { |file| file.puts(changed_lines.join) } end + + def with_env_vars(env_hash, &block) + current_values = {} + env_hash.each do |k,v| + current_values[k] = v + ENV[k] = v + end + block.call if block_given? + env_hash.each do |k,v| + ENV[k] = current_values[k] + end + end end end |