Class: RSpec::Mocks::LiveMessageExpectation

Inherits:
MessageExpectation
  • Object
show all
Defined in:
lib/rspec/mocks-call-through.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_double, *args, &block) ⇒ LiveMessageExpectation

Returns a new instance of LiveMessageExpectation.



35
36
37
38
# File 'lib/rspec/mocks-call-through.rb', line 35

def initialize(method_double, *args, &block)
  @method_double = method_double
  super(*args, &block)
end

Instance Attribute Details

#method_doubleObject (readonly)

Returns the value of attribute method_double.



33
34
35
# File 'lib/rspec/mocks-call-through.rb', line 33

def method_double
  @method_double
end

Instance Method Details

#and_call_throughObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rspec/mocks-call-through.rb', line 45

def and_call_through
  and_return { |*args|
    method_name = @method_double.obfuscate(@method_double.method_name)
    object = @method_double.object

    method = object.method(method_name)

    block = args.pop if args.last.kind_of?(Proc) && args.last.tainted?

    object.send(method_name, *args, &block)
  }
end

#invoke_return_block(*args, &block) ⇒ Object



40
41
42
43
# File 'lib/rspec/mocks-call-through.rb', line 40

def invoke_return_block(*args, &block)
  block.taint if block
  super(*args, &block)
end