summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMercedes Bernard <mercedesrbernard@gmail.com>2023-02-16 13:44:27 -0600
committergit <svn-admin@ruby-lang.org>2023-02-23 08:50:04 +0000
commite965133f56c2c7dca23d4172249aea056e2a449a (patch)
tree832529a9a51c726cd83f16487810d34bb69b2024 /spec
parent68995c21bed067c068e84ffc16181aee1c2f4fc9 (diff)
[rubygems/rubygems] test Bundler::Fetcher that error raised when attempting load unexpected class
https://github.com/rubygems/rubygems/commit/795e796a9e
Diffstat (limited to 'spec')
-rw-r--r--spec/bundler/bundler/fetcher_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb
index a104760075..9af3ec6b90 100644
--- a/spec/bundler/bundler/fetcher_spec.rb
+++ b/spec/bundler/bundler/fetcher_spec.rb
@@ -159,4 +159,34 @@ RSpec.describe Bundler::Fetcher do
end
end
end
+
+ describe "#fetch_spec" do
+ let(:name) { 'name' }
+ let(:version) { '1.3.17' }
+ let(:platform) { 'platform' }
+ let(:downloader) { double("downloader")}
+ let(:body) { double(Net::HTTP::Get, body: downloaded_data)}
+
+ context "when attempting to load a Gem::Specification" do
+ let(:spec) { Gem::Specification.new(name, version) }
+ let(:downloaded_data) { Zlib::Deflate.deflate(Marshal.dump(spec)) }
+
+ it "returns the spec" do
+ expect(Bundler::Fetcher::Downloader).to receive(:new).and_return(downloader)
+ expect(downloader).to receive(:fetch).once.and_return(body)
+ result = fetcher.fetch_spec([name, version, platform])
+ expect(result).to eq(spec)
+ end
+ end
+
+ context "when attempting to load an unexpected class" do
+ let(:downloaded_data) { Zlib::Deflate.deflate(Marshal.dump(3)) }
+
+ it "raises a HTTPError error" do
+ expect(Bundler::Fetcher::Downloader).to receive(:new).and_return(downloader)
+ expect(downloader).to receive(:fetch).once.and_return(body)
+ expect { fetcher.fetch_spec([name, version, platform]) }.to raise_error(Bundler::HTTPError, /Gemspec .* contained invalid data/i)
+ end
+ end
+ end
end