Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logic of register_default_spec #611

Merged
merged 4 commits into from
Aug 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1048,16 +1048,14 @@ class << self
#

def register_default_spec(spec)
new_format, prefix_pattern = nil
new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }

spec.files.each do |file|
if new_format == nil
new_format = spec.require_paths.any? {|path| file.start_with? path}

prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
prefix_pattern = /^(#{prefix_group})/
end
if new_format
prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
prefix_pattern = /^(#{prefix_group})/
end

spec.files.each do |file|
if new_format
file = file.sub(prefix_pattern, "")
next unless $~
Expand Down
7 changes: 7 additions & 0 deletions lib/rubygems/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,11 @@ def self.default_key_path
def self.default_cert_path
File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end

##
# Whether to expect full paths in default gems - true for non-MRI
# ruby implementations
def self.default_gems_use_full_paths?
ruby_engine != 'ruby'
end
end
22 changes: 22 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,28 @@ def test_register_default_spec
assert_equal nil, Gem.find_unresolved_default_spec("README")
end

def test_default_gems_use_full_paths
begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'ruby'
refute Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end

begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'jruby'
assert Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end
end

def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir)
Expand Down