summaryrefslogtreecommitdiff
path: root/test/ostruct/test_ostruct.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ostruct/test_ostruct.rb')
-rw-r--r--test/ostruct/test_ostruct.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index ef83db5d15..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
@@ -23,9 +38,23 @@ class TC_OpenStruct < Test::Unit::TestCase
def test_inspect
foo = OpenStruct.new
+ assert_equal("#<OpenStruct>", foo.inspect)
+ foo.bar = 1
+ foo.baz = 2
+ assert_equal("#<OpenStruct bar=1, baz=2>", foo.inspect)
+
+ foo = OpenStruct.new
foo.bar = OpenStruct.new
assert_equal('#<OpenStruct bar=#<OpenStruct>>', foo.inspect)
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