Pick testing and and you hit flexmock and flexstub.
So how do you use them? Here goes:
if condition method_2
If you want to test method_1's conditonal logic, with method_2 and method_3 stubbed out, here is how you do it with flexstub:
class MyTest< Test::Unit::TestCase
ca = CA.new
# do something to make the condition be true
# stub some methods of the instance
stub = flexstub(ca)
# Note: method_1 is invoked on ca.
# stub.method_1 will fail!
So when would you use flexmock?
If you wish to mock all the methods being called on an object, you may use a flexmock.
A flexmock is an object which will just receive the methods you set expectations for, using should_receive.
If you wish to mock only one of the methods of an object but the other methods need to be invoked with the real functionality,
use flexstub to mock only that particular method.
As you see, method_1 is invoked properly, but method_2 and method_3 are stubbed out.
One remarkable thing about this is mocking out an object's new method.
Anywhere Customer.new is called inside any class during your test, it will return a mock_customer.
This is quite powerful, because we no longer need to use dependancy injection for just test purposes.