* [PATCH] test/ruby/test_autoload: hoist out ruby_impl_require
@ 2015-11-05 21:57 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-11-05 21:57 UTC (permalink / raw)
To: spew
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-11-05 21:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-05 21:57 [PATCH] test/ruby/test_autoload: hoist out ruby_impl_require Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).