diff options
Diffstat (limited to 'test/ostruct')
-rw-r--r-- | test/ostruct/test_ostruct.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 8b0424d2d8..02c4c74152 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -164,4 +164,21 @@ class TC_OpenStruct < Test::Unit::TestCase e = assert_raise(ArgumentError) { os.send :foo=, true, true } assert_match(/#{__callee__}/, e.backtrace[0]) end + + def test_accessor_defines_method + os = OpenStruct.new(foo: 42) + assert os.respond_to? :foo + assert_equal([], os.singleton_methods) + assert_equal(42, os.foo) + assert_equal([:foo, :foo=], os.singleton_methods) + end + + def test_does_not_redefine + os = OpenStruct.new(foo: 42) + def os.foo + 43 + end + os.foo = 44 + assert_equal(43, os.foo) + end end |