Class: Facon::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-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

Constructor Details

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

Returns a new instance of Mock.



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

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



23
24
25
26
27
28
# File 'lib/motion-facon/mock.rb', line 23

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.



16
17
18
# File 'lib/motion-facon/mock.rb', line 16

def name
  @name
end