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



23
24
25
26
# File 'lib/bourne/api.rb', line 23

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



28
29
30
31
# File 'lib/bourne/api.rb', line 28

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

Instance Method Details

#does_not_match?(mock) ⇒ Boolean



48
49
50
51
# File 'lib/bourne/api.rb', line 48

def does_not_match?(mock)
  raise InvalidHaveReceived.new("should_not have_received(:#{@expected_method_name}) is invalid, please use" +
                                  " should have_received(:#{@expected_method_name}).never")
end

#failure_messageObject



53
54
55
56
57
58
59
# File 'lib/bourne/api.rb', line 53

def failure_message
  message  = ""
  if matching_stubs.empty?
    message << "unstubbed, "
  end
  message << @expectation.mocha_inspect
end

#matches?(mock) ⇒ Boolean



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bourne/api.rb', line 33

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
  invocation_count.times { @expectation.invoke }
  @expectation.verified?
end