diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-14 21:57:33 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-14 21:57:33 +0000 |
commit | 811e9923cf99350fc351b89fc944547114e7b70b (patch) | |
tree | 4791e0e805815250a0a3690a79f2c59bfa5afb9d /test/ruby/test_autoload.rb | |
parent | ace442901453e2c963fc3f210faaa237bfbafc1a (diff) | |
download | ruby-811e9923cf99350fc351b89fc944547114e7b70b.tar.gz |
* variable.c: Change autoload to call `require` through Ruby rather
than directly calling `rb_require_safe`. This allows things like
RubyGems to intercept file loading done though `autoload`.
[Feature #11140]
* test/ruby/test_autoload.rb: Test for change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_autoload.rb')
-rw-r--r-- | test/ruby/test_autoload.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index a95c27451b..5b1bbc0e0f 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -161,6 +161,31 @@ p Foo::Bar } end + def test_require_implemented_in_ruby_is_called + Kernel.module_eval do; alias :old_require :require; end + + called_with = [] + Kernel.send :define_method, :require do |path| + called_with << path + old_require path + end + + Tempfile.create(['autoload', '.rb']) {|file| + file.puts 'class AutoloadTest; end' + file.close + add_autoload(file.path) + begin + assert(Object::AutoloadTest) + ensure + remove_autoload_constant + end + assert_equal [file.path], called_with + } + + ensure + Kernel.module_eval do; alias :require :old_require; undef :old_require; end + end + def add_autoload(path) (@autoload_paths ||= []) << path eval <<-END |