From 6ec32b4aa50653fd2d0c583b5aadbe0c8620914c Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 26 May 2009 12:06:21 +0000 Subject: merge revision(s) 22332: * lib/ostruct.rb (OpenStruct#new_ostruct_member): checks if frozen. [ruby-talk:328195], [ruby-core:22142] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@23581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ostruct/test_ostruct.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 79662c6437..4d56102462 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -2,6 +2,21 @@ require 'test/unit' require 'ostruct' class TC_OpenStruct < Test::Unit::TestCase + def assert_not_respond_to(object, method, message="") + _wrap_assertion do + full_message = build_message(message, < +of type +expected not to respond_to\\?. +EOT + _wrap_assertion do + if object.respond_to?(method) + raise Test::Unit::AssertionFailedError, full_message, caller(5) + end + end + end + end + def test_equality o1 = OpenStruct.new o2 = OpenStruct.new @@ -34,4 +49,12 @@ class TC_OpenStruct < Test::Unit::TestCase foo.bar.foo = foo assert_equal('#>>', foo.inspect) end + + def test_frozen + o = OpenStruct.new + o.a = 'a' + o.freeze + assert_raise(TypeError) {o.b = 'b'} + assert_not_respond_to(o, :b) + end end -- cgit v1.2.3