Class: Facon::Mock
- Inherits:
-
Object
- Object
- Facon::Mock
- 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
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, stubs = {}) ⇒ Mock
constructor
A new instance of Mock.
- #method_missing(method, *args, &block) ⇒ Object
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.(method, *args) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/motion-facon/mock.rb', line 16 def name @name end |