Module: Mocha::API

Defined in:
lib/bourne/api.rb

Defined Under Namespace

Classes: HaveReceived, InvalidHaveReceived

Instance Method Summary collapse

Instance Method Details

#assert_received(mock, expected_method_name) {|matcher| ... } ⇒ Object

Asserts that the given mock received the given method.

Examples:

assert_received(mock, :to_s)
assert_received(Radio, :new) {|expect| expect.with(1041) }
assert_received(radio, :volume) {|expect| expect.with(11).twice }

Yields:

  • (matcher)


13
14
15
16
17
# File 'lib/bourne/api.rb', line 13

def assert_received(mock, expected_method_name)
  matcher = have_received(expected_method_name)
  yield(matcher) if block_given?
  assert matcher.matches?(mock), matcher.failure_message
end

#have_received(expected_method_name) ⇒ Object

:call-seq:

should have_received(method).with(arguments).times(times)

Ensures that the given mock received the given method.

Examples:

mock.should have_received(:to_s)
Radio.should have_received(:new).with(1041)
radio.should have_received(:volume).with(11).twice


100
101
102
# File 'lib/bourne/api.rb', line 100

def have_received(expected_method_name)
  HaveReceived.new(expected_method_name)
end