diff options
Diffstat (limited to 'test/ostruct/test_ostruct.rb')
-rw-r--r-- | test/ostruct/test_ostruct.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 4ec4d43084..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 @@ -405,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 |