summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_dependency.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_dependency.rb')
-rw-r--r--test/rubygems/test_gem_dependency.rb180
1 files changed, 100 insertions, 80 deletions
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index 828021c119..2a989a5551 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -1,8 +1,15 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/dependency'
+
+require_relative "helper"
+require "rubygems/dependency"
class TestGemDependency < Gem::TestCase
+ def setup
+ super
+
+ without_any_upwards_gemfiles
+ end
+
def test_initialize
d = dep "pkg", "> 1.0"
@@ -12,7 +19,7 @@ class TestGemDependency < Gem::TestCase
def test_initialize_type_bad
e = assert_raise ArgumentError do
- Gem::Dependency.new 'monkey' => '1.0'
+ Gem::Dependency.new "monkey" => "1.0"
end
assert_equal 'dependency name must be a String, was {"monkey"=>"1.0"}',
@@ -30,11 +37,11 @@ class TestGemDependency < Gem::TestCase
end
def test_initialize_prerelease
- d = dep 'd', '1.a'
+ d = dep "d", "1.a"
assert d.prerelease?
- d = dep 'd', '= 1.a'
+ d = dep "d", "= 1.a"
assert d.prerelease?
end
@@ -99,8 +106,13 @@ class TestGemDependency < Gem::TestCase
def test_equals_tilde_object
o = Object.new
- def o.name ; 'a' end
- def o.version ; '0' end
+ def o.name
+ "a"
+ end
+
+ def o.version
+ "0"
+ end
assert_match dep("a"), o
end
@@ -127,142 +139,142 @@ class TestGemDependency < Gem::TestCase
end
def test_match_eh_name_tuple
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_tup = Gem::NameTuple.new 'a', 1
- b_tup = Gem::NameTuple.new 'b', 2
- c_tup = Gem::NameTuple.new 'c', '2.a'
+ a_tup = Gem::NameTuple.new "a", 1
+ b_tup = Gem::NameTuple.new "b", 2
+ c_tup = Gem::NameTuple.new "c", "2.a"
assert a_dep.match? a_tup
refute a_dep.match? b_tup
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_tup
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
refute c_dep.match? c_tup
- c_dep = dep 'c'
+ c_dep = dep "c"
refute c_dep.match? c_tup
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_tup
end
def test_match_eh_allow_prerelease
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_tup = Gem::NameTuple.new 'a', 1
- b_tup = Gem::NameTuple.new 'b', 2
- c_tup = Gem::NameTuple.new 'c', '2.a'
+ a_tup = Gem::NameTuple.new "a", 1
+ b_tup = Gem::NameTuple.new "b", 2
+ c_tup = Gem::NameTuple.new "c", "2.a"
assert a_dep.match? a_tup, nil, true
refute a_dep.match? b_tup, nil, true
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_tup, nil, true
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
assert c_dep.match? c_tup, nil, true
- c_dep = dep 'c'
+ c_dep = dep "c"
assert c_dep.match? c_tup, nil, true
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_tup, nil, true
end
def test_match_eh_specification
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_spec = util_spec 'a', 1
- b_spec = util_spec 'b', 2
- c_spec = util_spec 'c', '2.a'
+ a_spec = util_spec "a", 1
+ b_spec = util_spec "b", 2
+ c_spec = util_spec "c", "2.a"
assert a_dep.match? a_spec
refute a_dep.match? b_spec
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_spec
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
refute c_dep.match? c_spec
- c_dep = dep 'c'
+ c_dep = dep "c"
refute c_dep.match? c_spec
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_spec
end
def test_matches_spec_eh
- spec = util_spec 'b', 2
+ spec = util_spec "b", 2
- refute dep('a') .matches_spec?(spec), 'name mismatch'
- assert dep('b') .matches_spec?(spec), 'name match'
- refute dep('b', '= 1') .matches_spec?(spec), 'requirement mismatch'
- assert dep('b', '~> 2').matches_spec?(spec), 'requirement match'
+ refute dep("a") .matches_spec?(spec), "name mismatch"
+ assert dep("b") .matches_spec?(spec), "name match"
+ refute dep("b", "= 1") .matches_spec?(spec), "requirement mismatch"
+ assert dep("b", "~> 2").matches_spec?(spec), "requirement match"
end
def test_matches_spec_eh_prerelease
- spec = util_spec 'b', '2.1.a'
+ spec = util_spec "b", "2.1.a"
- refute dep('a') .matches_spec?(spec), 'name mismatch'
- assert dep('b') .matches_spec?(spec), 'name match'
- refute dep('b', '= 1') .matches_spec?(spec), 'requirement mismatch'
- assert dep('b', '~> 2') .matches_spec?(spec), 'requirement match'
- assert dep('b', '~> 2.a').matches_spec?(spec), 'prerelease requirement'
+ refute dep("a") .matches_spec?(spec), "name mismatch"
+ assert dep("b") .matches_spec?(spec), "name match"
+ refute dep("b", "= 1") .matches_spec?(spec), "requirement mismatch"
+ assert dep("b", "~> 2") .matches_spec?(spec), "requirement match"
+ assert dep("b", "~> 2.a").matches_spec?(spec), "prerelease requirement"
end
def test_merge
- a1 = dep 'a', '~> 1.0'
- a2 = dep 'a', '= 1.0'
+ a1 = dep "a", "~> 1.0"
+ a2 = dep "a", "= 1.0"
a3 = a1.merge a2
- assert_equal dep('a', '~> 1.0', '= 1.0'), a3
+ assert_equal dep("a", "~> 1.0", "= 1.0"), a3
end
def test_merge_default
- a1 = dep 'a'
- a2 = dep 'a', '1'
+ a1 = dep "a"
+ a2 = dep "a", "1"
a3 = a1.merge a2
- assert_equal dep('a', '1'), a3
+ assert_equal dep("a", "1"), a3
end
def test_merge_name_mismatch
- a = dep 'a'
- b = dep 'b'
+ a = dep "a"
+ b = dep "b"
e = assert_raise ArgumentError do
a.merge b
end
- assert_equal 'a (>= 0) and b (>= 0) have different names',
+ assert_equal "a (>= 0) and b (>= 0) have different names",
e.message
end
def test_merge_other_default
- a1 = dep 'a', '1'
- a2 = dep 'a'
+ a1 = dep "a", "1"
+ a2 = dep "a"
a3 = a1.merge a2
- assert_equal dep('a', '1'), a3
+ assert_equal dep("a", "1"), a3
end
def test_prerelease_eh
@@ -288,44 +300,44 @@ class TestGemDependency < Gem::TestCase
end
def test_specific
- refute dep('a', '> 1').specific?
+ refute dep("a", "> 1").specific?
- assert dep('a', '= 1').specific?
+ assert dep("a", "= 1").specific?
end
def test_to_spec
- a_1 = util_spec 'a', '1'
- a_2 = util_spec 'a', '2'
+ a_1 = util_spec "a", "1"
+ a_2 = util_spec "a", "2"
- a_dep = dep 'a', '>= 0'
+ a_dep = dep "a", ">= 0"
install_specs a_1, a_2
assert_equal a_2, a_dep.to_spec
end
def test_to_spec_prerelease
- a_1 = util_spec 'a', '1'
- a_1_1_a = util_spec 'a', '1.1.a'
+ a_1 = util_spec "a", "1"
+ a_1_1_a = util_spec "a", "1.1.a"
- a_dep = dep 'a', '>= 0'
+ a_dep = dep "a", ">= 0"
install_specs a_1, a_1_1_a
assert_equal a_1, a_dep.to_spec
- a_pre_dep = dep 'a', '>= 0'
+ a_pre_dep = dep "a", ">= 0"
a_pre_dep.prerelease = true
assert_equal a_1_1_a, a_pre_dep.to_spec
end
def test_to_specs_suggests_other_versions
- a = util_spec 'a', '1.0'
+ a = util_spec "a", "1.0"
install_specs a
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
dep = Gem::Dependency.new "a", "= 2.0"
@@ -338,41 +350,39 @@ class TestGemDependency < Gem::TestCase
end
def test_to_specs_respects_bundler_version
- b = util_spec 'bundler', '2.0.0.pre.1'
- b_1 = util_spec 'bundler', '1'
+ b = util_spec "bundler", "2.0.0.pre.1"
+ b_1 = util_spec "bundler", "1"
install_specs b, b_1
- b_file = File.join b.gem_dir, 'lib', 'bundler', 'setup.rb'
+ b_file = File.join b.gem_dir, "lib", "bundler", "setup.rb"
write_file b_file do |io|
- io.puts '# setup.rb'
+ io.puts "# setup.rb"
end
dep = Gem::Dependency.new "bundler", ">= 0.a"
assert_equal [b, b_1], dep.to_specs
- Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["3.5", "reason"]) do
- e = assert_raise Gem::MissingSpecVersionError do
- dep.to_specs
- end
+ require "rubygems/bundler_version_finder"
- assert_match "Could not find 'bundler' (3.5) required by reason.\nTo update to the latest version installed on your system, run `bundle update --bundler`.\nTo install the missing version, run `gem install bundler:3.5`\n", e.message
+ Gem::BundlerVersionFinder.stub(:bundler_version, Gem::Version.new("1")) do
+ assert_equal [b_1, b], dep.to_specs
end
- Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["2.0.0.pre.1", "reason"]) do
- assert_equal [b], dep.to_specs
+ Gem::BundlerVersionFinder.stub(:bundler_version, Gem::Version.new("2.0.0.pre.1")) do
+ assert_equal [b, b_1], dep.to_specs
end
end
def test_to_specs_indicates_total_gem_set_size
- a = util_spec 'a', '1.0'
+ a = util_spec "a", "1.0"
install_specs a
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
dep = Gem::Dependency.new "b", "= 2.0"
@@ -384,6 +394,16 @@ class TestGemDependency < Gem::TestCase
assert_match "Could not find 'b' (= 2.0) among 1 total gem(s)", e.message
end
+ def test_to_spec_with_only_prereleases
+ a_2_a_1 = util_spec "a", "2.a1"
+ a_2_a_2 = util_spec "a", "2.a2"
+ install_specs a_2_a_1, a_2_a_2
+
+ a_dep = dep "a", ">= 1"
+
+ assert_equal a_2_a_2, a_dep.to_spec
+ end
+
def test_identity
assert_equal dep("a", "= 1").identity, :released
assert_equal dep("a", "= 1.a").identity, :complete