Module: Marshal

Defined in:
lib/spy/core_ext/marshal.rb

Class Method Summary collapse

Class Method Details

.dump_with_mocks(*args) ⇒ Object Also known as: dump



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spy/core_ext/marshal.rb', line 4

def dump_with_mocks(*args)
  object = args.shift
  spies = Spy::Subroutine.get_spies(object)
  if spies.empty?
    return dump_without_mocks(*args.unshift(object))
  end

  spy_hook_options = spies.map do |spy|
    [spy.hook_opts, spy.unhook]
  end

  begin
    dump_without_mocks(*args.unshift(object.dup))
  ensure
    spy_hook_options.each do |hook_opts, spy|
      spy.hook(hook_opts)
    end
  end
end