From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS16276 5.196.0.0/16 X-Spam-Status: No, score=-0.7 required=3.0 tests=BAYES_00,RCVD_IN_XBL, RDNS_NONE shortcircuit=no autolearn=no version=3.3.2 X-Original-To: spew@80x24.org Received: from 80x24.org (unknown [5.196.67.41]) by dcvr.yhbt.net (Postfix) with ESMTP id B2CEB1F45E for ; Thu, 5 Nov 2015 21:57:37 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] test/ruby/test_autoload: hoist out ruby_impl_require Date: Thu, 5 Nov 2015 21:57:35 +0000 Message-Id: <20151105215735.22811-1-e@80x24.org> List-Id: Having "require" implemented in Ruby is the common case nowadays with RubyGems, so ensure it is easy-to-reuse the same code. --- test/ruby/test_autoload.rb | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index ed73138..719502d 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)} -- EW