summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-04-30 08:06:07 +0000
committerSamuel Giddins <segiddins@segiddins.me>2017-04-30 18:34:43 -0500
commit87850baf0a5605a9afd78a8c3a376621b01d99b6 (patch)
tree0e6a48915e2e5c4e634c5cf45b4b863ab4901515
parent8621063842075168bd0559f981326082a6605181 (diff)
downloadbundler-87850baf0a5605a9afd78a8c3a376621b01d99b6.tar.gz
Auto merge of #5614 - bundler:seg-test-default-gem-substitutes-are-activated, r=indirect
Test that default gem substitutes are properly activated This is currently failing on ruby trunk (cherry picked from commit ad5cd9ee66e45b6f243720107b751d2341b4261c)
-rw-r--r--.rubocop.yml3
-rw-r--r--lib/bundler/rubygems_integration.rb6
-rw-r--r--lib/bundler/runtime.rb35
-rw-r--r--spec/runtime/setup_spec.rb44
4 files changed, 75 insertions, 13 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index ded01cbb21..96c9106550 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -122,6 +122,9 @@ Metrics/CyclomaticComplexity:
Metrics/ParameterLists:
Enabled: false
+Metrics/BlockLength:
+ Enabled: false
+
# It will be obvious which code is complex, Rubocop should only lint simple
# rules for us.
Metrics/PerceivedComplexity:
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 66497add02..7283a326dd 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -74,12 +74,16 @@ module Bundler
def spec_missing_extensions?(spec, default = true)
return spec.missing_extensions? if spec.respond_to?(:missing_extensions?)
- return false if spec.respond_to?(:default_gem?) && spec.default_gem?
+ return false if spec_default_gem?(spec)
return false if spec.extensions.empty?
default
end
+ def spec_default_gem?(spec)
+ spec.respond_to?(:default_gem?) && spec.default_gem?
+ end
+
def stub_set_spec(stub, spec)
stub.instance_variable_set(:@spec, spec)
end
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 5bdc9dfa63..5540509d74 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -29,18 +29,7 @@ module Bundler
raise GemNotFound, "#{spec.full_name} is missing. Run `bundle install` to get it."
end
- if (activated_spec = Bundler.rubygems.loaded_specs(spec.name)) && activated_spec.version != spec.version
- e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
- "but your Gemfile requires #{spec.name} #{spec.version}. Prepending " \
- "`bundle exec` to your command may solve this."
- e.name = spec.name
- if e.respond_to?(:requirement=)
- e.requirement = Gem::Requirement.new(spec.version.to_s)
- else
- e.version_requirement = Gem::Requirement.new(spec.version.to_s)
- end
- raise e
- end
+ check_for_activated_spec!(spec)
Bundler.rubygems.mark_loaded(spec)
spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
@@ -305,5 +294,27 @@ module Bundler
output
end
+
+ def check_for_activated_spec!(spec)
+ return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
+ return if activated_spec.version == spec.version
+
+ suggestion = if Bundler.rubygems.spec_default_gem?(activated_spec)
+ "Since #{spec.name} is a default gem, you can either remove your dependency on it" \
+ " or try updating to a newer version of bundler that supports #{spec.name} as a default gem."
+ else
+ "Prepending `bundle exec` to your command may solve this."
+ end
+
+ e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
+ "but your Gemfile requires #{spec.name} #{spec.version}. #{suggestion}"
+ e.name = spec.name
+ if e.respond_to?(:requirement=)
+ e.requirement = Gem::Requirement.new(spec.version.to_s)
+ else
+ e.version_requirement = Gem::Requirement.new(spec.version.to_s)
+ end
+ raise e
+ end
end
end
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index b19a81e75f..120aa03d7e 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -1197,6 +1197,50 @@ end
expect(err).to eq("")
expect(out).to eq("{}")
end
+
+ let(:default_gems) do
+ ruby!(<<-RUBY).split("\n")
+ if Gem::Specification.is_a?(Enumerable)
+ puts Gem::Specification.select(&:default_gem?).map(&:name)
+ end
+ RUBY
+ end
+
+ it "activates newer versions of default gems" do
+ build_repo4 do
+ default_gems.each do |g|
+ build_gem g, "999999"
+ end
+ end
+
+ install_gemfile! <<-G
+ source "file:#{gem_repo4}"
+ #{default_gems}.each do |g|
+ gem g, "999999"
+ end
+ G
+
+ expect(the_bundle).to include_gems(*default_gems.map {|g| "#{g} 999999" })
+ end
+
+ it "activates older versions of default gems" do
+ build_repo4 do
+ default_gems.each do |g|
+ build_gem g, "0.0.0.a"
+ end
+ end
+
+ default_gems.reject! {|g| exemptions.include?(g) }
+
+ install_gemfile! <<-G
+ source "file:#{gem_repo4}"
+ #{default_gems}.each do |g|
+ gem g, "0.0.0.a"
+ end
+ G
+
+ expect(the_bundle).to include_gems(*default_gems.map {|g| "#{g} 0.0.0.a" })
+ end
end
end