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.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 1fd7d87811..19bb606145 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -280,6 +280,7 @@ class TC_OpenStruct < Test::Unit::TestCase
os = OpenStruct.new(method: :foo, hash: 42)
assert_equal(os.object_id, os.method!(:object_id).call)
assert_not_equal(42, os.hash!)
+ refute os.methods.include?(:"!~!")
end
def test_override_subclass
@@ -368,6 +369,18 @@ class TC_OpenStruct < Test::Unit::TestCase
RUBY
end if defined?(Ractor)
+ def test_access_methods_from_different_ractor
+ assert_ractor(<<~RUBY, require: 'ostruct')
+ os = OpenStruct.new
+ os.value = 100
+ r = Ractor.new(os) do |x|
+ v = x.value
+ Ractor.yield v
+ end
+ assert 100 == r.take
+ RUBY
+ end if defined?(Ractor)
+
def test_legacy_yaml
s = "--- !ruby/object:OpenStruct\ntable:\n :foo: 42\n"
o = YAML.safe_load(s, permitted_classes: [Symbol, OpenStruct])
@@ -393,4 +406,29 @@ class TC_OpenStruct < Test::Unit::TestCase
o2 = Marshal.load(Marshal.dump(o))
assert_equal o, o2
end
+
+ def test_class
+ os = OpenStruct.new(class: 'my-class', method: 'post')
+ assert_equal('my-class', os.class)
+ assert_equal(OpenStruct, os.class!)
+ end
+
+ has_performance_warnings = begin
+ Warning[:performance]
+ true
+ rescue NoMethodError, ArgumentError
+ false
+ end
+
+ if has_performance_warnings
+ def test_performance_warning
+ assert_in_out_err(
+ %w(-Ilib -rostruct -w -W:performance -e) + ['OpenStruct.new(a: 1)'],
+ "",
+ [],
+ ["-e:1: warning: OpenStruct use is discouraged for performance reasons"],
+ success: true,
+ )
+ end
+ end
end