summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_object.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 5ba44c8699..b0e561a206 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -232,10 +232,22 @@ class TestObject < Test::Unit::TestCase
end
def test_remove_instance_variable
- o = Object.new
- o.instance_eval { @foo = :foo }
- o.remove_instance_variable(:@foo)
- assert_equal(false, o.instance_variable_defined?(:@foo))
+ { 'T_OBJECT' => Object.new,
+ 'T_CLASS,T_MODULE' => Class.new(Object),
+ 'generic ivar' => '',
+ }.each do |desc, o|
+ assert_raises(NameError, "#{desc} iv removal raises before set") do
+ o.remove_instance_variable(:@foo)
+ end
+ o.instance_eval { @foo = :foo }
+ assert_equal(:foo, o.remove_instance_variable(:@foo),
+ "#{desc} iv removal returns original value")
+ assert_equal(false, o.instance_variable_defined?(:@foo),
+ "#{desc} iv removed succesfully")
+ assert_raises(NameError, "#{desc} iv removal raises after removal") do
+ o.remove_instance_variable(:@foo)
+ end
+ end
end
def test_convert_string