Class: Mocha::API::HaveReceived

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(expected_method_name) ⇒ HaveReceived

Returns a new instance of HaveReceived.



20
21
22
23
# File 'lib/bourne/api.rb', line 20

def initialize(expected_method_name)
  @expected_method_name = expected_method_name
  @expectations = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



25
26
27
28
# File 'lib/bourne/api.rb', line 25

def method_missing(method, *args, &block)
  @expectations << [method, args, block]
  self
end

Instance Method Details

#failure_messageObject



45
46
47
# File 'lib/bourne/api.rb', line 45

def failure_message
  @expectation.mocha_inspect
end

#matches?(mock) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bourne/api.rb', line 30

def matches?(mock)
  if mock.respond_to?(:mocha)
    @mock = mock.mocha
  else
    @mock = mock
  end

  @expectation = Expectation.new(@mock, @expected_method_name)
  @expectations.each do |method, args, block|
    @expectation.send(method, *args, &block)
  end
  @expectation.invocation_count = invocation_count
  @expectation.verified?
end