summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-06-14 01:13:10 +0000
committerColby Swandale <hello@colby.fyi>2018-07-10 23:02:45 +1000
commit7a95824cf791dd927d72f53a1f32a25e64f1063c (patch)
tree4ff70eab304b85f2bfa6d9b81029a8a8f3ab2f30
parenta3e8388a0e2bf707ebfbe8d3d113394778ee7fc1 (diff)
downloadbundler-7a95824cf791dd927d72f53a1f32a25e64f1063c.tar.gz
Auto merge of #6571 - bundler:colby/fix-git-gem-error-message, r=indirect
Check if source responds to `#remotes` before printing gem install error message ### What was the end-user problem that led to this PR? There is a bug that was introduced in #6211 that prints an error message during `bundle install` if a gem failed to be installed. The error message attempts to call the `#remotes` method on `Bundler::Source::Git` which it does not implement. ### What was your diagnosis of the problem? See #6563 ### What is your fix for the problem, implemented in this PR? Check if the `source` responds to `#remotes` before and return early ### Why did you choose this fix out of the possible options? This seems to be the most simplest fix without having to refactor a lot of code. (cherry picked from commit f358c36b580723a39c7dd72fafd883e59d9b05df)
-rw-r--r--lib/bundler/installer/gem_installer.rb8
-rw-r--r--spec/install/failure_spec.rb60
2 files changed, 65 insertions, 3 deletions
diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb
index a38f8d95be..d4ef4942e2 100644
--- a/lib/bundler/installer/gem_installer.rb
+++ b/lib/bundler/installer/gem_installer.rb
@@ -44,9 +44,11 @@ module Bundler
end
def gem_install_message
- remotes = spec.source.remotes
- if remotes.size == 1
- "Make sure that `gem install #{spec.name} -v '#{spec.version}' --source '#{remotes.first}'` succeeds before bundling."
+ source = spec.source
+ return unless source.respond_to?(:remotes)
+
+ if source.remotes.size == 1
+ "Make sure that `gem install #{spec.name} -v '#{spec.version}' --source '#{source.remotes.first}'` succeeds before bundling."
else
"Make sure that `gem install #{spec.name} -v '#{spec.version}'` succeeds before bundling."
end
diff --git a/spec/install/failure_spec.rb b/spec/install/failure_spec.rb
index ea97ac837b..2c0c84e771 100644
--- a/spec/install/failure_spec.rb
+++ b/spec/install/failure_spec.rb
@@ -29,6 +29,66 @@ In Gemfile:
M
end
+ context "when installing a git gem" do
+ it "does not tell the user to run 'gem install'" do
+ build_git "activesupport", "2.3.2", :path => lib_path("activesupport") do |s|
+ s.extensions << "Rakefile"
+ s.write "Rakefile", <<-RUBY
+ task :default do
+ abort "make installing activesupport-2.3.2 fail"
+ end
+ RUBY
+ end
+
+ install_gemfile <<-G
+ source "file:\/\/localhost#{gem_repo1}"
+ gem "rails"
+ gem "activesupport", :git => "#{lib_path("activesupport")}"
+ G
+
+ expect(last_command.bundler_err).to end_with(<<-M.strip)
+An error occurred while installing activesupport (2.3.2), and Bundler cannot continue.
+
+In Gemfile:
+ rails was resolved to 2.3.2, which depends on
+ actionmailer was resolved to 2.3.2, which depends on
+ activesupport
+ M
+ end
+ end
+
+ context "when installing a gem using a git block" do
+ it "does not tell the user to run 'gem install'" do
+ build_git "activesupport", "2.3.2", :path => lib_path("activesupport") do |s|
+ s.extensions << "Rakefile"
+ s.write "Rakefile", <<-RUBY
+ task :default do
+ abort "make installing activesupport-2.3.2 fail"
+ end
+ RUBY
+ end
+
+ install_gemfile <<-G
+ source "file:\/\/localhost#{gem_repo1}"
+ gem "rails"
+
+ git "#{lib_path("activesupport")}" do
+ gem "activesupport"
+ end
+ G
+
+ expect(last_command.bundler_err).to end_with(<<-M.strip)
+An error occurred while installing activesupport (2.3.2), and Bundler cannot continue.
+
+
+In Gemfile:
+ rails was resolved to 2.3.2, which depends on
+ actionmailer was resolved to 2.3.2, which depends on
+ activesupport
+ M
+ end
+ end
+
it "prints out the hint for the remote source when available" do
build_repo2 do
build_gem "activesupport", "2.3.2" do |s|