Project

General

Profile

Bug #12248 ยป 65ab980dbc13d1b8e95b7d1f7266406720718c24.patch

hsbt (Hiroshi SHIBATA), 04/05/2016 03:55 AM

View differences:

lib/rubygems/core_ext/kernel_require.rb
66 66

  
67 67
    begin
68 68
      RUBYGEMS_ACTIVATION_MONITOR.exit
69
      return gem_original_require(spec.to_fullpath(path) || path)
69
      return gem_original_require(path)
70 70
    end if spec
71 71

  
72 72
    # Attempt to find +path+ in any unresolved gems...
test/rubygems/test_require.rb
49 49
    end
50 50
  end
51 51

  
52
  # Providing -I on the commandline should always beat gems
53
  def test_dash_i_beats_gems
54
    a1 = new_spec "a", "1", {"b" => "= 1"}, "lib/test_gem_require_a.rb"
55
    b1 = new_spec "b", "1", {"c" => "> 0"}, "lib/b/c.rb"
56
    c1 = new_spec "c", "1", nil, "lib/c/c.rb"
57
    c2 = new_spec "c", "2", nil, "lib/c/c.rb"
58

  
59
    install_specs c1, c2, b1, a1
60

  
61
    dir = Dir.mktmpdir
62
    dash_i_arg = File.join Dir.mktmpdir, 'lib'
63

  
64
    c_rb = File.join dash_i_arg, 'b', 'c.rb'
65

  
66
    FileUtils.mkdir_p File.dirname c_rb
67
    File.open(c_rb, 'w') { |f| f.write "class Object; HELLO = 'world' end" }
68

  
69
    lp = $LOAD_PATH.dup
70

  
71
    # Pretend to provide a commandline argument that overrides a file in gem b
72
    $LOAD_PATH.unshift dash_i_arg
73

  
74
    assert_require 'test_gem_require_a'
75
    assert_require 'b/c' # this should be required from -I
76
    assert_equal "world", ::Object::HELLO
77
  ensure
78
    $LOAD_PATH.replace lp
79
    Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
80
  end
81

  
52 82
  def test_concurrent_require
53 83
    Object.const_set :FILE_ENTERED_LATCH, Latch.new(2)
54 84
    Object.const_set :FILE_EXIT_LATCH, Latch.new(1)