summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <hello@colby.fyi>2018-06-08 22:20:46 +1000
committerColby Swandale <hello@colby.fyi>2018-06-08 23:13:44 +1000
commit083c701e49a28923484c084c43c4dcd8be2d619f (patch)
tree2d12b77e6f55e5c707f488d8a423954c1acbdb11
parentc793c38a55559677573d28d4bfadd811e8508b48 (diff)
downloadbundler-colby/fix-git-gem-error-message.tar.gz
Check if source responds to `#remotes` before printing gem install error messagecolby/fix-git-gem-error-message
-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 d60d636949..e5e245f970 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 27abe9fcc3..588bd96ee2 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|