Class: Mocha::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/bourne/mock.rb

Overview

Overwrites #method_missing on Mocha::Mock so pass arguments to Mocha::Expectation#invoke so that an Invocation can be created.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bourne/mock.rb', line 8

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)
    matching_expectation_allowing_invocation.invoke(arguments, &block)
  else
    if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
      message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
      message << Mockery.instance.mocha_inspect
      raise ExpectationError.new(message, caller)
    else   
      target = if self.respond_to? :mocha
        self.mocha
      else
        mocha
      end
      Mockery.instance.invocation(target, symbol, arguments)
      nil
    end
  end
end