Method: Object#isolate

Defined in:
lib/caricature/core_ext/object.rb

#isolate(name = nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block) ⇒ Object Also known as: when_receiving, mock, stub



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/caricature/core_ext/object.rb', line 22

def isolate(name=nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block)
  iso = Caricature::Isolation.for(self, recorder, expectations)
  return iso unless name
  if block
    if block.arity > 0
      @expectation = iso.when_receiving(name, &block)
    else
      @expectation = iso.when_receiving(name)
      instance_eval &block
    end
  end
  iso
end