Patchwork is a PHP library that allows you to change user defined functions at runtime. This can be incredibly handy when testing. I'm by no means a Ruby expert but I heard that in the Ruby world they do this kind of stuff all the time during testing.

Here's a simple example of what Patchwork can do:

function myCounter($array)
{
    return count($array);
}

myCounter([1, 2]); // returns '2';

//now let's change the function
Patchwork\redefine('myCounter', function($array)
{
    return count($array) ? 'a lot of items' : 'empty';
});

myCounter([1, 2]); // returns 'a lot of items";

Read the implementation docs to learn how this works behind the scenes.