summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/rubygems_integration.rb6
-rw-r--r--spec/bundler/rubygems_integration_spec.rb25
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 2e4d01ffb9..c3e16e086c 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -300,7 +300,7 @@ module Bundler
def download_gem(spec, uri, path)
uri = Bundler.settings.mirror_for(uri)
fetcher = Gem::RemoteFetcher.new(configuration[:http_proxy])
- Bundler::Retry.new("download gem #{uri}", Gem::RemoteFetcher::FetchError).attempts do
+ Bundler::Retry.new("download gem from #{uri}").attempts do
fetcher.download(spec, uri, path)
end
end
@@ -736,7 +736,9 @@ module Bundler
uri = Bundler.settings.mirror_for(uri)
fetcher = gem_remote_fetcher
fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
- fetcher.download(spec, uri, path)
+ Bundler::Retry.new("download gem from #{uri}").attempts do
+ fetcher.download(spec, uri, path)
+ end
end
def gem_remote_fetcher
diff --git a/spec/bundler/rubygems_integration_spec.rb b/spec/bundler/rubygems_integration_spec.rb
index 37eb499e38..38ff9dae7e 100644
--- a/spec/bundler/rubygems_integration_spec.rb
+++ b/spec/bundler/rubygems_integration_spec.rb
@@ -54,6 +54,31 @@ RSpec.describe Bundler::RubygemsIntegration do
end
end
+ describe "#download_gem", :rubygems => ">= 2.0" do
+ let(:bundler_retry) { double(Bundler::Retry) }
+ let(:retry) { double("Bundler::Retry") }
+ let(:uri) { URI.parse("https://foo.bar") }
+ let(:path) { Gem.path.first }
+ let(:spec) do
+ spec = Bundler::RemoteSpecification.new("Foo", Gem::Version.new("2.5.2"),
+ Gem::Platform::RUBY, nil)
+ spec.remote = Bundler::Source::Rubygems::Remote.new(uri.to_s)
+ spec
+ end
+ let(:fetcher) { double("gem_remote_fetcher") }
+
+ it "succesfully downloads gem with retries" do
+ expect(Bundler.rubygems).to receive(:gem_remote_fetcher).and_return(fetcher)
+ expect(fetcher).to receive(:headers=).with("X-Gemfile-Source" => "https://foo.bar")
+ expect(Bundler::Retry).to receive(:new).with("download gem from #{uri}/").
+ and_return(bundler_retry)
+ expect(bundler_retry).to receive(:attempts).and_yield
+ expect(fetcher).to receive(:download).with(spec, uri, path)
+
+ Bundler.rubygems.download_gem(spec, uri, path)
+ end
+ end
+
describe "#fetch_all_remote_specs", :rubygems => ">= 2.0" do
let(:uri) { URI("https://example.com") }
let(:fetcher) { double("gem_remote_fetcher") }