Class: FlexMock::PartialMockProxy

Class | FlexMock::PartialMockProxy
In: | lib/flexmock/deprecated_methods.rb lib/flexmock/partial_mock.rb
Parent: | Object

######################################################################### PartialMockProxy is used to mate the mock framework to an existing object. The object is "enhanced" with a reference to a mock object (stored in `@flexmock_mock`). When the `should_receive` method is sent to the proxy, it overrides the existing object‘s method by creating singleton method that forwards to the mock. When testing is complete, PartialMockProxy will erase the mocking infrastructure from the object being mocked (e.g. remove instance variables and mock singleton methods).

### Methods

add_mock_method any_instance flexmock_container flexmock_container= flexmock_expectations_for flexmock_get flexmock_teardown flexmock_verify new new_instances should_receive

### Included Modules

Ordering

### Constants

MOCK_METHODS | = | [ :should_receive, :new_instances, :flexmock_get, :flexmock_teardown, :flexmock_verify |  | The following methods are added to partial mocks so that they can act like a mock.

### Attributes

mock | [R] |

### Public Class methods

new(obj, mock, safe_mode)

Initialize a PartialMockProxy object.

### Public Instance methods

add_mock_method(obj, method_name)
any_instance(&block)

any_instance is present for backwards compatibility with version 0.5.0. @deprecated

flexmock_container()

Forward to the mock‘s container.

flexmock_container=(container)

Set the proxy‘s mock container. This set value is ignored because the proxy always uses the container of its mock.

flexmock_expectations_for(method_name)

Forward the request for the expectation director to the mock.

flexmock_get()

Get the mock object for the partial mock.

flexmock_teardown()

Remove all traces of the mocking framework from the existing object.

flexmock_verify()

Verify that the mock has been properly called. After verification, detach the mocking infrastructure from the existing object.

new_instances.should_receive(...)
new_instances { |instance| instance.should_receive(...) }

new_instances is a short cut method for overriding the behavior of any new instances created via a mocked class object.

By default, new_instances will mock the behaviour of the :new method. If you wish to mock a different set of class methods, just pass a list of symbols to as arguments. (previous versions also mocked :allocate by default. If you need :allocate to be mocked, just request it explicitly).

For example, to stub only objects created by :make (and not :new), use:

       flexmock(ClassName).new_instances(:make).should_receive(...)

should_receive(:method_name)
should_receive(:method1, method2, ...)
should_receive(:meth1 => result1, :meth2 => result2, ...)

Declare that the partial mock should receive a message with the given name.

If more than one method name is given, then the mock object should expect to receive all the listed melthods. If a hash of method name/value pairs is given, then the each method will return the associated result. Any expectations applied to the result of `should_receive` will be applied to all the methods defined in the argument list.

An expectation object for the method name is returned as the result of this method. Further expectation constraints can be added by chaining to the result.

See Expectation for a list of declarators that can be used.

[Validate]