Class: Mocha::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/debugger/test/mocha_extensions.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *arguments, &block) ⇒ Object

We monkey-patch that method to be able to pass arguments to Expectation#invoke method



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/debugger/test/mocha_extensions.rb', line 29

def method_missing(symbol, *arguments, &block)
  if @responder and not @responder.respond_to?(symbol)
    raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}"
  end
  if matching_expectation_allowing_invocation = @expectations.match_allowing_invocation(symbol, *arguments)
    # We change this line - added arguments
    matching_expectation_allowing_invocation.invoke(arguments, &block)
  else
    if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
      # We change this line - added arguments
      matching_expectation.invoke(arguments, &block) if matching_expectation
      message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
      require 'mocha/mockery'
      message << Mockery.instance.mocha_inspect
      raise ExpectationError.new(message)
    end
  end
end