Skip to content

Fixed YAML serialization of a stubbed object.

Created by: myronmarston

Consider this code:

require 'rubygems'
require 'rspec/mocks'
require 'yaml'

Object.send(:include, RSpec::Mocks::Methods)
class MyStruct < Struct.new(:foo, :bar); end
k = MyStruct.new(7, "something")
k.stub(:bazz => 12)
yaml = k.to_yaml
k2 = YAML.load(yaml)

We get an error when this is run:

$ ruby yaml_example.rb 
/Users/mmarston/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `transfer': allocator undefined for Proc (TypeError)
        from /Users/mmarston/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `node_import'
        from /Users/mmarston/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `load'
        from /Users/mmarston/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `load'
        from yaml_example.rb:10

This is fixed by my commit.

Merge request reports