diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-05 22:05:06 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-05 22:05:06 +0000 |
commit | 7d0a3681271b3e86e361c74375be195ebd897c9b (patch) | |
tree | 4dcfd59d46579e2dc5c9133074acd44bf7ec45dc | |
parent | 72b785e07210c7419802caa3595fc03d84df2c3a (diff) | |
download | ruby-7d0a3681271b3e86e361c74375be195ebd897c9b.tar.gz |
test/ruby/test_autoload: hoist out ruby_impl_require
Having "require" implemented in Ruby is the common case nowadays
with RubyGems, so ensure it is easy-to-reuse the same logic for
future tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | test/ruby/test_autoload.rb | 33 |
2 files changed, 22 insertions, 15 deletions
@@ -1,3 +1,7 @@ +Fri Nov 6 06:59:37 2015 Eric Wong <e@80x24.org> + + * test/ruby/test_autoload: hoist out ruby_impl_require + Thu Nov 5 13:03:58 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * defs/id.def (token_ops): gather associations between IDs, diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index ed731388cd..719502d268 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -187,31 +187,34 @@ p Foo::Bar } end - def test_require_implemented_in_ruby_is_called + def ruby_impl_require 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 - } - + yield called_with ensure Kernel.module_eval do; alias :require :old_require; undef :old_require; end end + def test_require_implemented_in_ruby_is_called + ruby_impl_require do |called_with| + 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 + } + end + end + def add_autoload(path) (@autoload_paths ||= []) << path ::Object.class_eval {autoload(:AutoloadTest, path)} |