summaryrefslogtreecommitdiff
path: root/test/ostruct/test_ostruct.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-31 05:37:21 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-31 05:37:21 +0000
commit2f2a5c3ae9f9e7a4d09b1500de8d864f48d69cad (patch)
tree99f8057a25387d3cf7ec58a6fd53cb41bda03b2b /test/ostruct/test_ostruct.rb
parent99894e6c82054c893e6c9f5bccc181b97b8120ee (diff)
* lib/ostruct.rb: Fix new_ostruct_member to correctly avoid redefinition
[#11901] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ostruct/test_ostruct.rb')
-rw-r--r--test/ostruct/test_ostruct.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 8b0424d..02c4c74 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