diff options
author | jfrazx <jfrazx@users.noreply.github.com> | 2021-06-14 08:53:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 09:53:20 -0400 |
commit | 931ea7cfbec6d863cd8b48308804323704a2696c (patch) | |
tree | a2585c739c839d5aa86a4488244087d93dd95bb4 /test/ostruct | |
parent | 90cad6e14745d812f042df61a6455db022be7389 (diff) | |
download | ruby-931ea7cfbec6d863cd8b48308804323704a2696c.tar.gz |
Add fallback block to `OpenStruct#delete_field` (#1409)
Diffstat (limited to 'test/ostruct')
-rw-r--r-- | test/ostruct/test_ostruct.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 7773da46af..f8d184b011 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -89,7 +89,7 @@ class TC_OpenStruct < Test::Unit::TestCase a = o.delete_field :a assert_not_respond_to(o, :a, bug) assert_not_respond_to(o, :a=, bug) - assert_equal(a, 'a') + assert_equal('a', a) s = Object.new def s.to_sym :foo @@ -100,6 +100,16 @@ class TC_OpenStruct < Test::Unit::TestCase o.delete_field s assert_not_respond_to(o, :foo) assert_not_respond_to(o, :foo=) + + assert_raise(NameError) { o.delete_field(s) } + assert_equal(:bar, o.delete_field(s) { :bar }) + + o[s] = :foobar + assert_respond_to(o, :foo) + assert_respond_to(o, :foo=) + assert_equal(:foobar, o.delete_field(s) { :baz }) + + assert_equal(42, OpenStruct.new(foo: 42).delete_field(:foo) { :bug }) end def test_setter |