mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 20:44:00 +02:00
* test/ruby/test_method.rb: Add test for &-coersion of an
UnboundMethod. * test/ruby/test_module.rb: Add test for define_method given an UnboundMethod. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d50a8dd0bd
commit
cd3bf49898
2 changed files with 28 additions and 0 deletions
|
@ -652,6 +652,15 @@ class TestMethod < Test::Unit::TestCase
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unbound_method_proc_coerce
|
||||||
|
# '&' coercion of an UnboundMethod raises TypeError
|
||||||
|
assert_raise(TypeError) do
|
||||||
|
Class.new do
|
||||||
|
define_method('foo', &Object.instance_method(:to_s))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test___dir__
|
def test___dir__
|
||||||
assert_instance_of String, __dir__
|
assert_instance_of String, __dir__
|
||||||
assert_equal(File.dirname(File.realpath(__FILE__)), __dir__)
|
assert_equal(File.dirname(File.realpath(__FILE__)), __dir__)
|
||||||
|
|
|
@ -2011,6 +2011,25 @@ class TestModule < Test::Unit::TestCase
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_define_method_with_unbound_method
|
||||||
|
# Passing an UnboundMethod to define_method succeeds if it is from an ancestor
|
||||||
|
assert_nothing_raised do
|
||||||
|
cls = Class.new(String) do
|
||||||
|
define_method('foo', String.instance_method(:to_s))
|
||||||
|
end
|
||||||
|
|
||||||
|
obj = cls.new('bar')
|
||||||
|
assert_equal('bar', obj.foo)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Passing an UnboundMethod to define_method fails if it is not from an ancestor
|
||||||
|
assert_raise(TypeError) do
|
||||||
|
Class.new do
|
||||||
|
define_method('foo', String.instance_method(:to_s))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_top_method_is_private(method)
|
def assert_top_method_is_private(method)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue