Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5614 - bundler:seg-test-default-gem-substitutes-are-ac…
Browse files Browse the repository at this point in the history
…tivated, r=indirect

Test that default gem substitutes are properly activated

This is currently failing on ruby trunk
  • Loading branch information
bundlerbot committed Apr 30, 2017
2 parents 28e67dc + 17293b2 commit ad5cd9e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ def set_installed_by_version(spec, installed_by_version = Gem::VERSION)
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
Expand Down
35 changes: 23 additions & 12 deletions lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ def setup(*groups)
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) }
Expand Down Expand Up @@ -305,5 +294,27 @@ def remove_dir(dir, dry_run)

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
44 changes: 44 additions & 0 deletions spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,50 @@ def lock_with(ruby_version = nil)
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

Expand Down

0 comments on commit ad5cd9e

Please sign in to comment.