diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-26 12:06:21 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-26 12:06:21 +0000 |
commit | 6ec32b4aa50653fd2d0c583b5aadbe0c8620914c (patch) | |
tree | f8864a549d2554dcf2f20e6dbb1340cbcb86e4d3 /test/ostruct | |
parent | 54b48da267b0a75e0cc6366a9409be12fdf4dde5 (diff) |
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
Diffstat (limited to 'test/ostruct')
-rw-r--r-- | test/ostruct/test_ostruct.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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, <<EOT, object, object.class, method) +<?> +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('#<OpenStruct bar=#<OpenStruct foo=#<OpenStruct ...>>>', 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 |