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_proxy). 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

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

Public Instance methods

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

Forward to the mock‘s container.

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

Forward the request for the expectation director to the mock.

Get the mock object for the partial mock.

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

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

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(...)

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]