summaryrefslogtreecommitdiff
path: root/test/rubygems/test_require.rb
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-03-14 12:34:03 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-08-17 07:35:48 +0900
commit00cd5d74cecb6aa4a184e57e2b8246ef6e45d458 (patch)
tree2ff487a4b5e474ddd17bf2e083b4722d1a746b2b /test/rubygems/test_require.rb
parentd4feeb19361a4d7addf4779fb6bdc8e8c072093b (diff)
[rubygems/rubygems] [Require] Ensure -I beats a default gem
https://github.com/rubygems/rubygems/commit/6fbda98eb3
Diffstat (limited to 'test/rubygems/test_require.rb')
-rw-r--r--test/rubygems/test_require.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index f8e1d3f26ec..dc722f2e0f7 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -83,6 +83,39 @@ class TestGemRequire < Gem::TestCase
end
end
+ # Providing -I on the commandline should always beat gems
+ def test_dash_i_beats_default_gems
+ a1 = new_default_spec "a", "1", {"b" => "= 1"}, "test_gem_require_a.rb"
+ b1 = new_default_spec "b", "1", {"c" => "> 0"}, "b/c.rb"
+ c1 = new_default_spec "c", "1", nil, "c/c.rb"
+ c2 = new_default_spec "c", "2", nil, "c/c.rb"
+
+ install_default_specs c1, c2, b1, a1
+
+ dir = Dir.mktmpdir("test_require", @tempdir)
+ dash_i_arg = File.join dir, 'lib'
+
+ c_rb = File.join dash_i_arg, 'c', 'c.rb'
+
+ FileUtils.mkdir_p File.dirname c_rb
+ File.open(c_rb, 'w') { |f| f.write "class Object; HELLO = 'world' end" }
+
+ assert_require 'test_gem_require_a'
+
+ lp = $LOAD_PATH.dup
+
+ # Pretend to provide a commandline argument that overrides a file in gem b
+ $LOAD_PATH.unshift dash_i_arg
+
+ assert_require 'b/c'
+ assert_require 'c/c' # this should be required from -I
+ assert_equal "world", ::Object::HELLO
+ assert_equal %w(a-1 b-1), loaded_spec_names
+ ensure
+ $LOAD_PATH.replace lp
+ Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
+ end
+
def test_concurrent_require
Object.const_set :FILE_ENTERED_LATCH, Latch.new(2)
Object.const_set :FILE_EXIT_LATCH, Latch.new(1)