From acc55c25c587fef5c7327c5912f3aa50a969ec34 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 6 Mar 2012 03:06:11 +0000 Subject: merge revision(s) 34919: * lib/yaml/rubytypes.rb (Exception.yaml_new): fix bug that causes YAML serialization problem for Exception. Exception#initialize doesn't use visible instance variable for the exception message, so call the method with the message. patched by Jingwen Owen Ou . http://github.com/ruby/ruby/pull/41 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@34920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/yaml/test_exception.rb | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/yaml/test_exception.rb (limited to 'test') diff --git a/test/yaml/test_exception.rb b/test/yaml/test_exception.rb new file mode 100644 index 0000000000..1dc3044a94 --- /dev/null +++ b/test/yaml/test_exception.rb @@ -0,0 +1,52 @@ +require 'test/unit' +require 'yaml' + +module Syck + class TestException < Test::Unit::TestCase + class Wups < Exception + attr_reader :foo, :bar + def initialize *args + super + @foo = 1 + @bar = 2 + end + + def ==(other) + self.class == other.class and + self.message == other.message and + self.backtrace == other.backtrace + end + end + + def setup + @wups = Wups.new('test_message') + end + + def test_to_yaml + w = YAML.load(@wups.to_yaml) + assert_equal @wups, w + assert_equal 1, w.foo + assert_equal 2, w.bar + end + + def test_dump + w = YAML.load(@wups.to_yaml) + assert_equal @wups, w + assert_equal 1, w.foo + assert_equal 2, w.bar + end + + def test_to_yaml_properties + class << @wups + def to_yaml_properties + [:@foo] + end + end + + w = YAML.load(YAML.dump(@wups)) + assert_equal @wups, w + assert_equal 1, w.foo + assert_nil w.bar + end + end +end -- cgit v1.2.3