module Facon::Mockable

A module containing convenient methods for creating mocks, stubs and expectations.

Public Instance Methods

mock(name, stubs = {}) click to toggle source

Shortcut for creating a Facon::Mock instance.

Example

mock = mock('test mock', :foo => 'bar')
mock.foo # => 'bar'
# File lib/facon/mockable.rb, line 12
def mock(name, stubs = {})
  Mock.new(name, stubs)
end
mock_proxy() click to toggle source

Returns the mock proxy object.

# File lib/facon/mockable.rb, line 39
def mock_proxy
  @mock_proxy ||= Proxy.new(self, Mock === self ? @name : self.class.name)
end
should_not_receive(method, &block) click to toggle source
# File lib/facon/mockable.rb, line 24
def should_not_receive(method, &block)
  mock_proxy.add_negative_expectation(caller(1)[0], method, &block)
end
should_receive(method, &block) click to toggle source
# File lib/facon/mockable.rb, line 20
def should_receive(method, &block)
  mock_proxy.add_expectation(caller(1)[0], method, &block)
end
spec_reset() click to toggle source
# File lib/facon/mockable.rb, line 34
def spec_reset
  mock_proxy.reset
end
spec_verify() click to toggle source

Verifies that the expectations set on this mock are all met, otherwise raises a MockExpectationError.

# File lib/facon/mockable.rb, line 30
def spec_verify
  mock_proxy.verify
end
stub!(method) click to toggle source
# File lib/facon/mockable.rb, line 16
def stub!(method)
  mock_proxy.add_stub(caller(1)[0], method)
end