Class: RSpec::Mocks::MarshalExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/marshal_extension.rb

Overview

Support for ‘patch_marshal_to_support_partial_doubles` configuration.

Class Method Summary collapse

Class Method Details

.patch!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/marshal_extension.rb', line 7

def self.patch!
  return if Marshal.respond_to?(:dump_with_rspec_mocks)

  Marshal.instance_eval do
    class << self
      def dump_with_rspec_mocks(object, *rest)
        if !::RSpec::Mocks.space.registered?(object) || NilClass === object
          dump_without_rspec_mocks(object, *rest)
        else
          dump_without_rspec_mocks(object.dup, *rest)
        end
      end

      alias_method :dump_without_rspec_mocks, :dump
      undef_method :dump
      alias_method :dump, :dump_with_rspec_mocks
    end
  end
end

.unpatch!Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/marshal_extension.rb', line 27

def self.unpatch!
  return unless Marshal.respond_to?(:dump_with_rspec_mocks)

  Marshal.instance_eval do
    class << self
      undef_method :dump_with_rspec_mocks
      undef_method :dump
      alias_method :dump, :dump_without_rspec_mocks
      undef_method :dump_without_rspec_mocks
    end
  end
end