aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 5b5e04b0da..4f834f0c1e 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -240,7 +240,7 @@ class TestModule < Test::Unit::TestCase
assert_not_operator(Math, :const_defined?, "IP")
end
- def test_bad_constants
+ def each_bad_constants(m, &b)
[
"#<Class:0x7b8b718b>",
":Object",
@@ -248,15 +248,28 @@ class TestModule < Test::Unit::TestCase
":",
["String::", "[Bug #7573]"],
"\u3042",
+ "Name?",
].each do |name, msg|
expected = "wrong constant name %s" % quote(name)
msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}"
- assert_raise_with_message(NameError, expected, msg) {
- Object.const_get name
- }
+ assert_raise_with_message(NameError, expected, "#{msg} to #{m}") do
+ yield name
+ end
end
end
+ def test_bad_constants_get
+ each_bad_constants("get") {|name|
+ Object.const_get name
+ }
+ end
+
+ def test_bad_constants_defined
+ each_bad_constants("defined?") {|name|
+ Object.const_defined? name
+ }
+ end
+
def test_leading_colons
assert_equal Object, AClass.const_get('::Object')
end