Permalink
Browse files

Fix Marshal serialization of stubbed objects

- Closes #27.
  • Loading branch information...
1 parent 6084658 commit 80ee73dc34e9f0f27079f1ba53ecf9a0378e153c @txus txus committed with dchelimsky Oct 15, 2010
@@ -0,0 +1,25 @@
+module Marshal
+
+ class << self
+
+ def dump_with_mocks(*args)
+ object = args.shift
+ return dump_without_mocks(*args.unshift(object)) unless object.instance_variable_defined?(:@mock_proxy)
+
+ mp = object.instance_variable_get(:@mock_proxy)
+ object.send(:remove_instance_variable, :@mock_proxy)
+
+ begin
+ dump_without_mocks(*args.unshift(object.dup))
+ ensure
+ object.instance_variable_set(:@mock_proxy,mp)
+ end
+ end
+
+ alias_method :dump_without_mocks, :dump
+ undef_method :dump
+ alias_method :dump, :dump_with_mocks
+
+ end
+
+end
@@ -1,3 +1,5 @@
+require 'rspec/mocks/extensions/marshal'
+
module RSpec
module Mocks
module Serialization
@@ -60,9 +60,7 @@ def set_stub
end
it 'marshals the same with and without stubbing' do
- pending("not sure how to fix this yet") do
- expect { set_stub }.to_not change { Marshal.dump(subject) }
- end
+ expect { set_stub }.to_not change { Marshal.dump(subject) }
end
end
end

0 comments on commit 80ee73d

Please sign in to comment.