spec/shared-examples/git/bare_repository.rb in r10k-2.2.2 vs spec/shared-examples/git/bare_repository.rb in r10k-2.3.0

- old
+ new

@@ -15,10 +15,41 @@ it "creates the repo at the expected location" do subject.clone(remote) config = File.read(File.join(basedir, dirname, 'config')) expect(config).to match(remote) end + + context "without a proxy" do + before(:each) do + allow(R10K::Git).to receive(:get_proxy_for_remote).with(remote).and_return(nil) + end + + it 'does not change proxy ENV' do + expect(ENV).to_not receive(:[]=) + expect(ENV).to_not receive(:update) + + subject.clone(remote) + end + end + + context "with a proxy" do + before(:each) do + allow(R10K::Git).to receive(:get_proxy_for_remote).with(remote).and_return('http://proxy.example.com:3128') + end + + it "manages proxy-related ENV vars" do + # Sets proxy settings. + ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy'].each do |var| + expect(ENV).to receive(:[]=).with(var, 'http://proxy.example.com:3128') + end + + # Resets proxy settings when done. + expect(ENV).to receive(:update).with(hash_including('HTTPS_PROXY' => nil)) + + subject.clone(remote) + end + end end describe "updating the repo" do let(:tag_090) { subject.git_dir + 'refs' + 'tags' + '0.9.0' } let(:packed_refs) { subject.git_dir + 'packed-refs' } @@ -31,9 +62,40 @@ it "fetches objects from the remote" do expect(subject.tags).to_not include('0.9.0') subject.fetch expect(subject.tags).to include('0.9.0') + end + + context "without a proxy" do + before(:each) do + allow(R10K::Git).to receive(:get_proxy_for_remote).with(remote).and_return(nil) + end + + it 'does not change proxy ENV' do + expect(ENV).to_not receive(:[]=) + expect(ENV).to_not receive(:update) + + subject.fetch + end + end + + context "with a proxy" do + before(:each) do + allow(R10K::Git).to receive(:get_proxy_for_remote).with(remote).and_return('http://proxy.example.com:3128') + end + + it "manages proxy-related ENV vars" do + # Sets proxy settings. + ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy'].each do |var| + expect(ENV).to receive(:[]=).with(var, 'http://proxy.example.com:3128') + end + + # Resets proxy settings when done. + expect(ENV).to receive(:update).with(hash_including('HTTPS_PROXY' => nil)) + + subject.fetch + end end end describe "listing branches" do before do