Module: Facon::Mockable

Included in:
Mock, Object
Defined in:
lib/facon/mockable.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#mock(name, stubs = {}) ⇒ Object

Shortcut for creating a Facon::Mock instance.

Example

mock = mock('test mock', :foo => 'bar')
mock.foo # => 'bar'


12
13
14
# File 'lib/facon/mockable.rb', line 12

def mock(name, stubs = {})
  Mock.new(name, stubs)
end

#mock_proxyObject

Returns the mock proxy object.



39
40
41
# 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) ⇒ Object



24
25
26
# 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) ⇒ Object



20
21
22
# File 'lib/facon/mockable.rb', line 20

def should_receive(method, &block)
  mock_proxy.add_expectation(caller(1)[0], method, &block)
end

#spec_resetObject



34
35
36
# File 'lib/facon/mockable.rb', line 34

def spec_reset
  mock_proxy.reset
end

#spec_verifyObject

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



30
31
32
# File 'lib/facon/mockable.rb', line 30

def spec_verify
  mock_proxy.verify
end

#stub!(method) ⇒ Object



16
17
18
# File 'lib/facon/mockable.rb', line 16

def stub!(method)
  mock_proxy.add_stub(caller(1)[0], method)
end