forked from rspec/rspec-mocks
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix yaml serialization when using Psych.
Without these changes, I was getting SystemStackErrors when calling YAML.dump(stubbed_object) or stubbed_object.to_yaml. To test this, you may need to reinstall ruby 1.9.2 with psych support. On OSX with homebrew and rvm, this will do the trick: brew install libyaml rvm install ruby-1.9.2 --with-libyaml-dir=/usr/local Closes rspec#36.
- Loading branch information
1 parent
0f09860
commit 8ce0c12
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Psych | ||
class << self | ||
def dump_with_mocks(object, *args) | ||
return dump_without_mocks(object, *args) unless object.instance_variable_defined?(:@mock_proxy) | ||
|
||
mp = object.instance_variable_get(:@mock_proxy) | ||
return dump_without_mocks(object, *args) unless mp.is_a?(::RSpec::Mocks::Proxy) | ||
|
||
object.send(:remove_instance_variable, :@mock_proxy) | ||
|
||
begin | ||
dump_without_mocks(object, *args) | ||
ensure | ||
object.instance_variable_set(:@mock_proxy,mp) | ||
end | ||
end | ||
|
||
alias_method :dump_without_mocks, :dump | ||
alias_method :dump, :dump_with_mocks | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters