summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler/fetcher/index_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/bundler/fetcher/index_spec.rb')
-rw-r--r--spec/bundler/bundler/fetcher/index_spec.rb117
1 files changed, 49 insertions, 68 deletions
diff --git a/spec/bundler/bundler/fetcher/index_spec.rb b/spec/bundler/bundler/fetcher/index_spec.rb
index 5ecd7d9e05..b8ce46321e 100644
--- a/spec/bundler/bundler/fetcher/index_spec.rb
+++ b/spec/bundler/bundler/fetcher/index_spec.rb
@@ -17,100 +17,81 @@ RSpec.describe Bundler::Fetcher::Index do
end
context "error handling" do
- shared_examples_for "the error is properly handled" do
- let(:remote_uri) { Bundler::URI("http://remote-uri.org") }
- before do
- allow(subject).to receive(:remote_uri).and_return(remote_uri)
- end
+ let(:remote_uri) { Bundler::URI("http://remote-uri.org") }
+ before do
+ allow(rubygems).to receive(:fetch_all_remote_specs) { raise Gem::RemoteFetcher::FetchError.new(error_message, display_uri) }
+ allow(subject).to receive(:remote_uri).and_return(remote_uri)
+ end
- context "when certificate verify failed" do
- let(:error_message) { "certificate verify failed" }
+ context "when certificate verify failed" do
+ let(:error_message) { "certificate verify failed" }
- it "should raise a Bundler::Fetcher::CertificateFailureError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::CertificateFailureError,
- %r{Could not verify the SSL certificate for http://sample_uri.com})
- end
+ it "should raise a Bundler::Fetcher::CertificateFailureError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::CertificateFailureError,
+ %r{Could not verify the SSL certificate for http://sample_uri.com})
end
+ end
- context "when a 401 response occurs" do
- let(:error_message) { "401" }
-
- before do
- allow(remote_uri).to receive(:userinfo).and_return(userinfo)
- end
-
- context "and there was userinfo" do
- let(:userinfo) { double(:userinfo) }
+ context "when a 401 response occurs" do
+ let(:error_message) { "401" }
- it "should raise a Bundler::Fetcher::BadAuthenticationError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError,
- %r{Bad username or password for http://remote-uri.org})
- end
- end
+ before do
+ allow(remote_uri).to receive(:userinfo).and_return(userinfo)
+ end
- context "and there was no userinfo" do
- let(:userinfo) { nil }
+ context "and there was userinfo" do
+ let(:userinfo) { double(:userinfo) }
- it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError,
- %r{Authentication is required for http://remote-uri.org})
- end
+ it "should raise a Bundler::Fetcher::BadAuthenticationError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError,
+ %r{Bad username or password for http://remote-uri.org})
end
end
- context "when a 403 response occurs" do
- let(:error_message) { "403" }
+ context "and there was no userinfo" do
+ let(:userinfo) { nil }
- before do
- allow(remote_uri).to receive(:userinfo).and_return(userinfo)
+ it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError,
+ %r{Authentication is required for http://remote-uri.org})
end
+ end
+ end
- context "and there was userinfo" do
- let(:userinfo) { double(:userinfo) }
+ context "when a 403 response occurs" do
+ let(:error_message) { "403" }
- it "should raise a Bundler::Fetcher::BadAuthenticationError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError,
- %r{Bad username or password for http://remote-uri.org})
- end
- end
+ before do
+ allow(remote_uri).to receive(:userinfo).and_return(userinfo)
+ end
- context "and there was no userinfo" do
- let(:userinfo) { nil }
+ context "and there was userinfo" do
+ let(:userinfo) { double(:userinfo) }
- it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError,
- %r{Authentication is required for http://remote-uri.org})
- end
+ it "should raise a Bundler::Fetcher::BadAuthenticationError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError,
+ %r{Bad username or password for http://remote-uri.org})
end
end
- context "any other message is returned" do
- let(:error_message) { "You get an error, you get an error!" }
-
- before { allow(Bundler).to receive(:ui).and_return(double(:trace => nil)) }
+ context "and there was no userinfo" do
+ let(:userinfo) { nil }
- it "should raise a Bundler::HTTPError" do
- expect { subject.specs(gem_names) }.to raise_error(Bundler::HTTPError, "Could not fetch specs from http://sample_uri.com")
+ it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError,
+ %r{Authentication is required for http://remote-uri.org})
end
end
end
- context "when a Gem::RemoteFetcher::FetchError occurs" do
- before { allow(rubygems).to receive(:fetch_all_remote_specs) { raise Gem::RemoteFetcher::FetchError.new(error_message, nil) } }
+ context "any other message is returned" do
+ let(:error_message) { "You get an error, you get an error!" }
- it_behaves_like "the error is properly handled"
- end
+ before { allow(Bundler).to receive(:ui).and_return(double(:trace => nil)) }
- context "when a OpenSSL::SSL::SSLError occurs" do
- before { allow(rubygems).to receive(:fetch_all_remote_specs) { raise OpenSSL::SSL::SSLError.new(error_message) } }
-
- it_behaves_like "the error is properly handled"
- end
-
- context "when a Net::HTTPFatalError occurs" do
- before { allow(rubygems).to receive(:fetch_all_remote_specs) { raise Net::HTTPFatalError.new(error_message, 404) } }
-
- it_behaves_like "the error is properly handled"
+ it "should raise a Bundler::HTTPError" do
+ expect { subject.specs(gem_names) }.to raise_error(Bundler::HTTPError, "Could not fetch specs from http://sample_uri.com due to underlying error <You get an error, you get an error! (http://sample_uri.com)>")
+ end
end
end
end