diff options
| -rw-r--r-- | lib/bundler/definition.rb | 18 | ||||
| -rw-r--r-- | lib/bundler/dsl.rb | 13 | ||||
| -rw-r--r-- | spec/bundler/bundler/dsl_spec.rb | 17 | ||||
| -rw-r--r-- | spec/bundler/commands/install_spec.rb | 31 |
4 files changed, 41 insertions, 38 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 9ce38209d6..84b7236a1f 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -608,10 +608,20 @@ module Bundler missing_specs.each do |s| locked_gem = @locked_specs[s.name].last next if locked_gem.nil? || locked_gem.version != s.version || sources.local_mode? - raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \ - "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \ - "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \ - "removed in order to install." + + message = if sources.implicit_global_source? + "Because your Gemfile specifies no global remote source, your bundle is locked to " \ + "#{locked_gem} from #{locked_gem.source}. However, #{locked_gem} is not installed. You'll " \ + "need to either add a global remote source to your Gemfile or make sure #{locked_gem} is " \ + "available locally before rerunning Bundler." + else + "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \ + "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \ + "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \ + "removed in order to install." + end + + raise GemNotFound, message end missing_specs_list = missing_specs.group_by(&:source).map do |source, missing_specs_for_source| diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index df904f074a..a7b7df84a6 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -503,18 +503,7 @@ module Bundler end def check_rubygems_source_safety - if @sources.implicit_global_source? - implicit_global_source_warning - elsif @sources.aggregate_global_source? - multiple_global_source_warning - end - end - - def implicit_global_source_warning - Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \ - "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run. " \ - "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"." + multiple_global_source_warning if @sources.aggregate_global_source? end def multiple_global_source_warning diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb index 7b6d080593..c4f9d0dbb5 100644 --- a/spec/bundler/bundler/dsl_spec.rb +++ b/spec/bundler/bundler/dsl_spec.rb @@ -350,21 +350,4 @@ RSpec.describe Bundler::Dsl do end end end - - describe "#check_primary_source_safety" do - context "when a global source is not defined implicitly" do - it "will raise a major deprecation warning" do - not_a_global_source = double("not-a-global-source", no_remotes?: true) - allow(Bundler::Source::Rubygems).to receive(:new).and_return(not_a_global_source) - - warning = "This Gemfile does not include an explicit global source. " \ - "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run. " \ - "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"." - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, warning) - - subject.check_primary_source_safety - end - end - end end diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 6c9e06f3b8..9a4006faaa 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -340,15 +340,36 @@ RSpec.describe "bundle install with gem sources" do expect(the_bundle).to include_gems "myrack 1.2", "activesupport 1.2.3" end - it "gives a useful error if no sources are set" do + it "gives useful errors if no global sources are set, and gems not installed locally, with and without a lockfile" do install_gemfile <<-G, raise_on_error: false gem "myrack" G - expect(err).to include("This Gemfile does not include an explicit global source. " \ - "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run. " \ - "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\".") + expect(err).to eq("Could not find gem 'myrack' in locally installed gems.") + + lockfile <<~L + GEM + specs: + myrack (1.0.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + myrack + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "install", raise_on_error: false + + expect(err).to include( + "Because your Gemfile specifies no global remote source, your bundle is locked to " \ + "myrack (1.0.0) from locally installed gems. However, myrack (1.0.0) is not installed. " \ + "You'll need to either add a global remote source to your Gemfile or make sure myrack (1.0.0) " \ + "is available locally before rerunning Bundler." + ) end it "creates a Gemfile.lock on a blank Gemfile" do |
