Class: Facon::Mock

Inherits:
Object show all
Includes:
Mockable
Defined in:
lib/facon/mock.rb

Overview

A mock object is a ‘fake’ object on which you can impose simulated behavior. Defining expectations and stubs on mock objects allows you to specify object collaboration without needing to actually instantiate those collaborative objects.

Examples

mock = mock('A name')
mock = mock('Mock person', :name => 'Konata', :sex => 'female')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mockable

#mock, #mock_proxy, #should_not_receive, #should_receive, #spec_reset, #spec_verify, #stub!

Constructor Details

#initialize(name, stubs = {}) ⇒ Mock

Returns a new instance of Mock.



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

def initialize(name, stubs = {})
  @name = name
  stub_out(stubs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



25
26
27
28
29
30
# File 'lib/facon/mock.rb', line 25

def method_missing(method, *args, &block)
  super(method, *args, &block)
rescue NameError
  # An unexpected method was called on this mock.
  mock_proxy.raise_unexpected_message_error(method, *args)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/facon/mock.rb', line 18

def name
  @name
end