Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions lib/rubygems/resolver/api_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,24 @@ def pretty_print(q) # :nodoc:
# Fetches a Gem::Specification for this APISpecification.

def spec # :nodoc:
@spec ||=
begin
tuple = Gem::NameTuple.new @name, @version, @platform
source.fetch_spec tuple
rescue Gem::RemoteFetcher::FetchError
raise if @original_platform == @platform

tuple = Gem::NameTuple.new @name, @version, @original_platform
source.fetch_spec tuple
end
@spec ||= build_minimal_spec_from_compact_index
end

def source # :nodoc:
@set.source
end

private

def build_minimal_spec_from_compact_index
spec = Gem::Specification.new
spec.name = @name
spec.version = @version
spec.platform = @platform
spec.dependencies.replace(@dependencies)
spec.required_ruby_version = @required_ruby_version
spec.required_rubygems_version = @required_rubygems_version

spec
end
end
19 changes: 19 additions & 0 deletions test/rubygems/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,25 @@ def write_marshalled_gemspecs(*all_specs)
end
end

##
# Sets up Compact Index API endpoints for testing. Does NOT set up old marshal API.
# This causes Source#new_dependency_resolver_set to use APISet.
#
# Usage:
# compact_index do |ci|
# ci.gem "a", 1 do |s|
# s.add_dependency "b", ">= 2.0"
# end
# ci.gem "b", 2
# end

def compact_index(&block)
fake_compact_index = Gem::TestCase::CompactIndexSetup.new(self, @gem_repo)
yield fake_compact_index
fake_compact_index.stub
fake_compact_index.specs
end

##
# Deflates +data+

Expand Down
134 changes: 81 additions & 53 deletions test/rubygems/test_gem_commands_install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def teardown
end

def test_execute_exclude_prerelease
spec_fetcher do |fetcher|
fetcher.gem "a", 2
fetcher.gem "a", "2.pre"
compact_index do |ci|
ci.gem "a", 2
ci.gem "a", "2.pre"
end

@cmd.options[:args] = %w[a]
Expand All @@ -46,9 +46,9 @@ def test_execute_exclude_prerelease
end

def test_execute_explicit_version_includes_prerelease
specs = spec_fetcher do |fetcher|
fetcher.gem "a", 2
fetcher.gem "a", "2.a"
specs = compact_index do |ci|
ci.gem "a", 2
ci.gem "a", "2.a"
end

a2_pre = specs["a-2.a"]
Expand Down Expand Up @@ -430,9 +430,9 @@ def test_execute_nonexistent_with_dashes
end

def test_execute_prerelease_skipped_when_no_flag_set
spec_fetcher do |fetcher|
fetcher.gem "a", 1
fetcher.gem "a", "3.a"
compact_index do |ci|
ci.gem "a", 1
ci.gem "a", "3.a"
end

@cmd.options[:prerelease] = false
Expand Down Expand Up @@ -483,9 +483,9 @@ def test_execute_with_version_specified_by_colon
end

def test_execute_prerelease_skipped_when_non_pre_available
spec_fetcher do |fetcher|
fetcher.gem "a", "2.pre"
fetcher.gem "a", 2
compact_index do |ci|
ci.gem "a", "2.pre"
ci.gem "a", 2
end

@cmd.options[:prerelease] = true
Expand Down Expand Up @@ -532,9 +532,9 @@ def test_execute_required_ruby_version

def test_execute_required_ruby_version_upper_bound
local = Gem::Platform.local
spec_fetcher do |fetcher|
fetcher.gem "a", 2.0
fetcher.gem "a", 2.0 do |s|
compact_index do |ci|
ci.gem "a", 2.0
ci.gem "a", 2.0 do |s|
s.required_ruby_version = "< #{RUBY_VERSION}.a"
s.platform = local
end
Expand All @@ -552,8 +552,8 @@ def test_execute_required_ruby_version_upper_bound
end

def test_execute_required_ruby_version_specific_not_met
spec_fetcher do |fetcher|
fetcher.gem "a", "1.0" do |s|
compact_index do |ci|
ci.gem "a", "1.0" do |s|
s.required_ruby_version = "= 1.4.6"
end
end
Expand All @@ -572,8 +572,8 @@ def test_execute_required_ruby_version_specific_not_met
end

def test_execute_required_ruby_version_specific_prerelease_met
spec_fetcher do |fetcher|
fetcher.gem "a", "1.0" do |s|
compact_index do |ci|
ci.gem "a", "1.0" do |s|
s.required_ruby_version = ">= 1.4.6.preview2"
end
end
Expand All @@ -592,8 +592,8 @@ def test_execute_required_ruby_version_specific_prerelease_met
def test_execute_required_ruby_version_specific_prerelease_not_met
next_ruby_pre = Gem.ruby_version.segments.map.with_index {|n, i| i == 1 ? n + 1 : n }.join(".") + ".a"

spec_fetcher do |fetcher|
fetcher.gem "a", "1.0" do |s|
compact_index do |ci|
ci.gem "a", "1.0" do |s|
s.required_ruby_version = "> #{next_ruby_pre}"
end
end
Expand All @@ -612,8 +612,8 @@ def test_execute_required_ruby_version_specific_prerelease_not_met
end

def test_execute_required_rubygems_version_wrong
spec_fetcher do |fetcher|
fetcher.gem "a", "1.0" do |s|
compact_index do |ci|
ci.gem "a", "1.0" do |s|
s.required_rubygems_version = "< 0"
end
end
Expand All @@ -632,8 +632,8 @@ def test_execute_required_rubygems_version_wrong
end

def test_execute_rdoc
specs = spec_fetcher do |fetcher|
fetcher.gem "a", 2
specs = compact_index do |ci|
ci.gem "a", 2
end

Gem.done_installing(&Gem::RDoc.method(:generation_hook))
Expand Down Expand Up @@ -661,8 +661,8 @@ def test_execute_rdoc
end if defined?(Gem::RDoc) && !Gem.rdoc_hooks_defined_via_plugin?

def test_execute_rdoc_with_path
specs = spec_fetcher do |fetcher|
fetcher.gem "a", 2
specs = compact_index do |ci|
ci.gem "a", 2
end

Gem.done_installing(&Gem::RDoc.method(:generation_hook))
Expand Down Expand Up @@ -690,8 +690,8 @@ def test_execute_rdoc_with_path
end if defined?(Gem::RDoc) && !Gem.rdoc_hooks_defined_via_plugin?

def test_execute_saves_build_args
specs = spec_fetcher do |fetcher|
fetcher.gem "a", 2
specs = compact_index do |ci|
ci.gem "a", 2
end

args = %w[--with-awesome=true --more-awesome=yes]
Expand Down Expand Up @@ -720,8 +720,8 @@ def test_execute_saves_build_args
end

def test_execute_remote
spec_fetcher do |fetcher|
fetcher.gem "a", 2
compact_index do |ci|
ci.gem "a", 2
end

@cmd.options[:args] = %w[a]
Expand All @@ -740,8 +740,8 @@ def test_execute_remote
def test_execute_with_invalid_gem_file
FileUtils.touch("a.gem")

spec_fetcher do |fetcher|
fetcher.gem "a", 2
compact_index do |ci|
ci.gem "a", 2
end

@cmd.options[:args] = %w[a]
Expand All @@ -758,8 +758,8 @@ def test_execute_with_invalid_gem_file
end

def test_execute_remote_truncates_existing_gemspecs
spec_fetcher do |fetcher|
fetcher.gem "a", 1
compact_index do |ci|
ci.gem "a", 1
end

@cmd.options[:domain] = :remote
Expand Down Expand Up @@ -791,9 +791,9 @@ def test_execute_remote_truncates_existing_gemspecs
end

def test_execute_remote_ignores_files
specs = spec_fetcher do |fetcher|
fetcher.gem "a", 1
fetcher.gem "a", 2
specs = compact_index do |ci|
ci.gem "a", 1
ci.gem "a", 2
end

@cmd.options[:domain] = :remote
Expand Down Expand Up @@ -887,11 +887,11 @@ def test_execute_two_version
end

def test_execute_two_version_specified_by_colon
spec_fetcher do |fetcher|
fetcher.gem "a", 1
fetcher.gem "a", 2
fetcher.gem "b", 1
fetcher.gem "b", 2
compact_index do |ci|
ci.gem "a", 1
ci.gem "a", 2
ci.gem "b", 1
ci.gem "b", 2
end

@cmd.options[:args] = %w[a:1 b:1]
Expand Down Expand Up @@ -956,8 +956,8 @@ def test_install_gem_ignore_dependencies_both
end

def test_install_gem_ignore_dependencies_remote
spec_fetcher do |fetcher|
fetcher.gem "a", 2
compact_index do |ci|
ci.gem "a", 2
end

@cmd.options[:ignore_dependencies] = true
Expand All @@ -969,10 +969,10 @@ def test_install_gem_ignore_dependencies_remote

def test_install_gem_ignore_dependencies_remote_platform_local
local = Gem::Platform.local
spec_fetcher do |fetcher|
fetcher.gem "a", 3
compact_index do |ci|
ci.gem "a", 3

fetcher.gem "a", 3 do |s|
ci.gem "a", 3 do |s|
s.platform = local
end
end
Expand Down Expand Up @@ -1365,9 +1365,9 @@ def test_execute_with_gemdeps_path_ignores_system
end

def test_execute_uses_deps_a_gemdeps_with_a_path
specs = spec_fetcher do |fetcher|
fetcher.gem "q", "1.0"
fetcher.gem "r", "2.0", "q" => nil
specs = compact_index do |ci|
ci.gem "q", "1.0"
ci.gem "r", "2.0", "q" => nil
end

i = Gem::Installer.at specs["q-1.0"].cache_file, install_dir: "gf-path"
Expand Down Expand Up @@ -1568,8 +1568,8 @@ def test_explain_platform_ruby_ignore_dependencies

def test_suggest_update_if_enabled
TestUpdateSuggestion.with_eligible_environment(cmd: @cmd) do
spec_fetcher do |fetcher|
fetcher.gem "a", 2
compact_index do |ci|
ci.gem "a", 2
end

@cmd.options[:args] = %w[a]
Expand Down Expand Up @@ -1642,4 +1642,32 @@ def test_execute_bindir_with_nonexistent_parent_dirs

assert_equal %w[a-2], @cmd.installed_specs.map(&:full_name)
end

def test_install_from_compact_index_only_source
compact_index do |ci|
ci.gem "main-gem", "2" do |s|
s.add_dependency "dep-gem", ">= 1.0"
end
ci.gem "dep-gem", "1"
end

@cmd.options[:args] = %w[main-gem]

use_ui @ui do
assert_raise Gem::MockGemUi::SystemExitException, @ui.error do
@cmd.execute
end
end

assert_equal %w[dep-gem-1 main-gem-2], @cmd.installed_specs.map(&:full_name).sort

installed_gem = @cmd.installed_specs.find {|s| s.name == "main-gem" }
assert_equal "main-gem", installed_gem.name
assert_equal Gem::Version.new("2"), installed_gem.version
assert_equal 1, installed_gem.dependencies.size
assert_equal "dep-gem", installed_gem.dependencies.first.name

marshal_requests = @fetcher.paths.select {|p| p.include?("/quick/Marshal.4.8/") }
assert_empty marshal_requests, "Should not request marshal gemspecs: #{marshal_requests.inspect}"
end
end
Loading